Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-28-2003, 03:11 PM
|
#1
|
Member
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129
Rep:
|
check for existence of file
How can I determine if a file exists in a directory?
I'm trying to re-write an old 6.2 script that does not work on RH8.0. A file get ftp'd from the mainframe to this server. A cron job runs @the 20th of every hour to see if the file exists, If it does, then it manipulates the file and prepares for processing.
Code:
if test -e /home/me/myfile
then
mv /home/me/myfile /home/you/send/
|
|
|
07-28-2003, 03:13 PM
|
#2
|
Member
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129
Original Poster
Rep:
|
I hit enter accidentally.
cp /home/me/myfile /home/you/backup/$DAY/
fi
|
|
|
07-28-2003, 03:21 PM
|
#3
|
Senior Member
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552
Rep:
|
if [ -f /home/me/myfile ]
then
echo found
fi
|
|
|
07-28-2003, 03:52 PM
|
#4
|
Member
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129
Original Poster
Rep:
|
#!/bin/sh
if [ -f /home/me/myfile ]
then
echo 'found'
fi
i get : No such file or directory.
but if i go to the directory, ls shows the file.
# ls
myfile
if i remove the #!/bin/sh
: unexpected end of file
hmm?
|
|
|
07-28-2003, 05:49 PM
|
#5
|
Senior Member
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120
Rep:
|
Still very much in the infancy of shell scripting land and better way to do i guess but that worked for me
Quote:
if find /home/me/myfile >/dev/null 2>&1
then
echo file found
fi
|
|
|
|
07-29-2003, 08:58 AM
|
#6
|
Member
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129
Original Poster
Rep:
|
okay, here's results.
I had ftpd this from the 6.2 box to 8.0 box. So I decided to just retype the whole bloody script fresh in a new file. By golly they both worked. The error was referencing an error past the last line of the script which did not make sense. That's why I decided to retype it thinking something happened in the ftp process.
Anyway, it now appears to work just peachy.
Thanks for input.
Cheers!
|
|
|
All times are GMT -5. The time now is 12:17 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|