Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CRON wont run sh script

Posted on 2010-11-17
10
Medium Priority
?
1,028 Views
Last Modified: 2012-05-10
Can someone tell me why my script wont fun fron cron??  It runs fine from the command line.  And the cron log doesn't output any errors either.

Here is the script:

#!/bin/sh
clear

echo "This script is starting"
echo  "Backup starting please wait..."
echo "Removing old backup..."
if [ -e "/www_backups/wwwback.tgz" ]
then
	rm /www_backups/wwwback.tgz
fi
if [ -e "/www_backups/sqlbackup.sql.gz" ]
then
	rm /www_backups/sqlbackup.sql.gz
fi
mysqldump -u XXXX -pXXXXXX digitald_trucking | gzip -9c > /www_backups/sqlbackup.sql.gz

tar -cvzf /www_backups/wwwback.tgz --exclude=/var/www/sqlbackups /var/www >/dev/nul
echo "Backup complete"
echo "Now emailing file"
sendEmail -f xxxx@localhost.com -t xxxxxx@gmail.com -u WWW Backup for DB -m backup -a /www_backups/wwwback.tgz
sendEmail -f xxxx@localhost.com -t xxxxxx@gmail.com -u DB backup  -m sql backup -a /www_backups/sqlbackup.sql.gz

rm /www_backups/wwwback.tgz
rm /www_backups/sqlbackup.sql.gz

Open in new window


I have given it execute permissions: 0755
and here is my crontab log

Nov 17 19:53:01 lamp /usr/sbin/cron[4539]: (root) RELOAD (crontabs/root)
Nov 17 19:54:58 lamp crontab[21890]: (root) LIST (root)
Nov 17 19:55:01 lamp /USR/SBIN/CRON[21892]: (root) CMD (sh /scripts/wwwback.sh)


Sorry I have placed XXXX's where sensitive information would be.

Is it a path problem? Permissions?
0
Comment
Question by:drhamel69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 23

Expert Comment

by:savone
ID: 34160884
Does it need to run as root?  Is it in roots crontab?

Can you post the ouotput of crontab -l

0
 
LVL 2

Author Comment

by:drhamel69
ID: 34160918
root@lamp:~# crontab -l
57 9 * * * /etc/webmin/cron/tempdelete.pl
0 3 * * * /etc/webmin/mysql/backup.pl --all
0,15 3 * * * /etc/webmin/mysql/backup.pl digitald_trucking
55 1,19 * * * sh /scripts/wwwback.sh

here is the crontab output.  I think it runs as root.  Could the problem be that I wrote the script logged in as root and I am scheduling it with Webmin?
0
 
LVL 2

Author Comment

by:drhamel69
ID: 34160980
I am almost wondering if the job is actually running but there is a problem calling the perl script SendEmail from cron.  the only notification that I get that the job runs is the emails I get generated by the 2 sendEmail lines.  Any ideas?
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 
LVL 23

Expert Comment

by:savone
ID: 34160989
try putting it in crontab like

55 1,19 * * * /scripts/wwwback.sh

You shouldn't need the sh, that is if you are running it from the command line.

also, what distro are you using?  Are you sure it shouldnt be a bash script, in that case you should have
#!/bin/bash
on the first line.
0
 
LVL 23

Expert Comment

by:savone
ID: 34160996
also can you run this command and paste it here:

cd /bin; ls -l s*
0
 
LVL 2

Author Comment

by:drhamel69
ID: 34161005
I am running turnkey lamp.  Whichi is based of off Ubuntu.  I originally had #!/bin/sh and had it in cron without the SH.  That didn't work either.

root@lamp:/bin# ot@lamp:/bin# ls -cd /bin; ls -l s*
-bash: ot@lamp:/bin#: No such file or directory
-rwxr-xr-x 1 root root   450 Sep 30  2009 search-path
-rwxr-xr-x 1 root root 40724 Dec  4  2007 sed
-rwxr-xr-x 1 root root   538 Sep 30  2009 select_mountoptions
-rwxr-xr-x 1 root root  1485 Sep 30  2009 select_mountpoint
-rwxr-xr-x 1 root root 30568 Feb  4  2008 setfont
-rwxr-xr-x 1 root root  8431 Nov 27  2008 setupcon
lrwxrwxrwx 1 root root     4 Feb  7  2010 sh -> dash
lrwxrwxrwx 1 root root     4 Feb  7  2010 sh.distrib -> bash
-rwxr-xr-x 1 root root 24488 Apr  4  2008 sleep
-rwxr-xr-x 1 root root  3188 Sep 30  2009 stralign
-rwxr-xr-x 1 root root 48932 Apr  4  2008 stty
-rwsr-xr-x 1 root root 25540 Dec  8  2008 su
-rwxr-xr-x 1 root root 22312 Apr  4  2008 sync
-rwxr-xr-x 1 root root  1288 Sep 30  2009 sysfs-update-devnames
0
 
LVL 23

Accepted Solution

by:
savone earned 1000 total points
ID: 34161071
Hmmm.. I am not familiar with ubuntu/debian so I do not know anything about the dash shell.. Your sh is linked to dash, which is a debian specific shell.  That could be the problem, but since I am not familiar with it, and it runs on the command line I would say its not a problem.

I would take the sh out of your crontab file like this:
55 1,19 * * * /scripts/wwwback.sh

and see if that helps.
0
 
LVL 2

Assisted Solution

by:drhamel69
drhamel69 earned 0 total points
ID: 34161193
Thanks for eveyones help but I fixed it myself.  After all the input it made me think that I didn't have the absolute path to the sendEmail perl script.  Once I added /usr/local/bin in front of it it worked no problems.

Thanks Everyone!
0
 
LVL 2

Author Comment

by:drhamel69
ID: 34161200
done
0
 
LVL 2

Author Closing Comment

by:drhamel69
ID: 34186483
Even though I figured out the solution for myself the comments by other users really made me think AND take other issues that it could have been out of the loop.

Thanks,
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question