LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   SUSE / openSUSE (https://www.linuxquestions.org/questions/suse-opensuse-60/)
-   -   IF command (https://www.linuxquestions.org/questions/suse-opensuse-60/if-command-815440/)

s_linux 06-21-2010 10:27 AM

IF command
 
Hi All,
I have a script
Quote:

# Call mail script to send an email
if [ -f /tmp/report.txt ]; then
/usr/local/scripts/mail.pl
sleep 10
rm /tmp/report.txt
else
exit
fi
What I need to do is, I want to check if file exists, if file exists call other script (mail.pl)and then delete the file (assuming mail.pl script executed). If file not exists just exit out of the script.

I'm not sure how I can see that other script execution completed or not before I delete the file even though I put sleep command.

And also it seems like its not that good, even though it is working. I wanted to see if we can write in more efficient way.
Any help appreciated.

timmeke 06-21-2010 10:33 AM

Try catching the return code from mail.pl, by checking $? right after the mail.pl executed.

Another option could be to check mail.pl's prints on standard output (stdout) or standard error (stderr), if it prints anything.

Or maybe you can start by explaining what mail.pl actually does?

s_linux 06-21-2010 10:40 AM

Thanks,
mail.pl script just sends an email. I can not add mail command in main script bcz it does not work. don't ask me why.

But my main concern is write the same script in efficient way.
Thanks

pixellany 06-21-2010 10:47 AM

Quote:

Originally Posted by s_linux (Post 4010344)
Thanks,
mail.pl script just sends an email. I can not add mail command in main script bcz it does not work. don't ask me why.

OK--I won't ask--I'll just suggest that you figure out why the "mail" command does not work. Assuming that it works as expected in a real-time terminal session, then you really DO want to know why it does not work in a script.

Please no texting shorthand here----because

s_linux 06-21-2010 10:51 AM

Yes that will be the my next step to figure out why its not working.


Thanks


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