LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 07-28-2003, 02:11 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Rep: Reputation: 16
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/
 
Old 07-28-2003, 02:13 PM   #2
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
I hit enter accidentally.

cp /home/me/myfile /home/you/backup/$DAY/

fi
 
Old 07-28-2003, 02:21 PM   #3
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
if [ -f /home/me/myfile ]
then
echo found
fi
 
Old 07-28-2003, 02:52 PM   #4
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
#!/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?
 
Old 07-28-2003, 04:49 PM   #5
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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
 
Old 07-29-2003, 07:58 AM   #6
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script that checks for existence of files Rotwang Linux - General 3 12-02-2005 02:11 PM
how does grub knows about existence of other OS? mohit_garg Linux - Newbie 29 07-13-2005 07:24 PM
Device existence problem..... roshu Mandriva 2 02-07-2005 06:01 AM
Scanner's temporal existence phantompgr Fedora 0 10-14-2004 06:51 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM


All times are GMT -5. The time now is 12:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration