Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
This will run every 5 Minutes an "ls" and append the output at the end of /tmp/ls.txt , but not all can understand "/5", then use "5,10,15,..."
Check is the owner of the crontab (=the user you edited with) has the permissions to do that.
My script dosent work when i run it as a cron job.
this works when run from the shell.
what might be the reason it is soo.
the script jus redirects a commands output to a file .it the serches the file for a pattern usin grep and execute some commands if the pattern is found.
cd /take/to/the/directory
. ./test.1>test_out
. ./test.2>>test_out
grep -q "somethin" test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com<test_out
fi
grep -q "somethin_agen" test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com<test_out
fi
How do you call it in the crontab ( /take/to/the/directory/test.1> test_out ) ?
It's better to use crontab just to call other scripts, without any parameters (it may work, but not on all plattforms).
You can direct the output of a script in itself by "exec >> /var/xyz.log".
Originally posted by sanjith11 My script dosent work when i run it as a cron job.
this works when run from the shell.
what might be the reason it is soo.
the script jus redirects a commands output to a file .it the serches the file for a pattern usin grep and execute some commands if the pattern is found.
cd /take/to/the/directory
. ./test.1>test_out
. ./test.2>>test_out
grep -q "somethin" test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com<test_out
fi
grep -q "somethin_agen" test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com<test_out
fi
*test.1 and test.2 are properly working scripts
I would say it's because you aren't using complete path names. Also check the test.1 and test.2 and make sure they have full pathnames.
I would change the scripts to something like this:
###########################################
/take/to/the/directory/test.1 > /take/to/the/directory/test_out
/take/to/the/directory/test.2 >> /take/to/the/directory/test_out
grep -q "somethin" /take/to/the/directory/test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com< /take/to/the/directory/test_out
fi
grep -q "somethin_agen" /take/to/the/directory/test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com< /take/to/the/directory/test_out
fi
###########################################
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.