Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If file exists 2

Status
Not open for further replies.

dodge20

MIS
Joined
Jan 15, 2003
Messages
1,048
Location
US
I have this script

echo "\nEnter the password: \n"
read pword
echo "\nEnter the time to run ex. 1700: \c"
read time
echo "\nEnter the month to run ex. Dec: \c"
read month
echo "\nEnter the Day to run ex 09: \c"
read day

cd /usr/ias/tmp/"$pword"
rm I*;rm M*;rm G*;rm K*;rm H*;rm W*;rm *;
cd /usr/ias/bin
at "$time" nohup ht.make.lists "$pword">/dev/null &


This works fine, if the file exists in the tmp directory. But if there is no file, I get an error message. What I would like to do is create a statement that checks if the file exists, and if it does, then run the rm. If it doesn't, then I would just like to skip over this. I think it can be done with an if statement, but I don't know who to check if the file exists?

I hope I made sense.

Dodge20
 
have you changed shells? or anything else changed lately?
try this
#!/bin/sh
echo "\nEnter the password: \c"; read pword
echo "\nEnter the time to run ex. 1700: \c";read time
echo "\nEnter the month to run ex. Dec: \c";read month
echo "\nEnter the Day to run ex 09: \c"; read day
mydir=/usr/ias/tmp/$pword
rm -rf $mydir
mkdir -p $mydir #maybe add chown and/or chmod
cd $mydir
cd /usr/ias/bin
at $time < ht.make.lists $pword >/dev/null
 
I am an idiot. The shell question triggered the fact that I am stupid. When I run this from the % prompt I am supposed to type

%sh ht.pm2

but I was typing

%ht.pm2

so it wasn't working correctly. I am sorry for the stupid question. I do appreciate the help with the script.

Dodge20
 
You could put #!/bin/sh on the beginning of the script to make sure that it always runs under that shell.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top