[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

Linux Cron not Execution Shell Script

Hi Experts,
I cannot get cron to backup my Firefox settings via a shell script.

I'm running ubuntu, v 7.10 on a celeron machine.

Daily, I run Firefoxr addon FEBE which backups up Firefox settings to a file.  The name of the file created by FEBE is: profile{default}.fbu.  The file is written to /bkup/FEBE/.

I wrote a shell script to copy profile{default}.fbu to another directory and append the Date -Time(YYYYMMDD-HHMMSS) to the file so it will not be over written the next day.   The shell script is shown below:

#!/bin/bash
mv /bkup/FEBE/profile*.fbu  /bkup/FEBE/daily/profile{default}.fbu-$(date +"%Y.%m.%d-%H.%M.%S")

I can successfully run the script from the command prompt, but I cannot get cron to execute it.  

Services anacron and atd are running.  I used KCron to  to set up cron.

The attached screen shot shows more information:

1. upper left - name and location of shell script
2. upper middle - KCron setup (not setup while root)
3. upper right - anacron service
4. bottom left - location and name of file to be backed up (created by Firefox FEBE)
5. bottom middle - shell script code - - note I use a "*"  to generalize file name in shell script


Can you see what I have done wrong?

Thanks much.
Screenshot.png
0
IT79637
Asked:
IT79637
3 Solutions
 
omarfaridCommented:
Please note that to run scripts as crontab jobs, you need:

- Set all required env variables in the script itself. e.g.

PATH=/usr/bin ; export PATH

- When you refer to commands or files please use full pathnames . e.g.

/usr/bin/mv

/usr/bin/date

These are used in your script.

- Redirect command output to a file to see results or errors. By default it is sent as mail to the user. You may check you email with mail command.

To redirect output:

/path/to/command >> /path/to/command.log 2>&1

0
 
arrkerr1024Commented:
Take a look at /var/log/cron and see if there are any errors.  The script has to be marked as executable (chmod 750 <script>), and cron can be picky about permissions.  If there is a permissions problem then it tell you exactly what is wrong in the log file.
0
 
ahoffmannCommented:
in your crontab use something like:

1 1 * * * /bin/mv "/bkup/FEBE/profile{default}.fbu"  "/bkup/FEBE/daily/profile{default}.fbu-$(date +'%Y.%m.%d-%H.%M.%S')"

Note, that you most likely cannot copy /bkup/FEBE/profile*.fbu to one single file 'cause it overwrites the same destination file, obviously ...
0
 
IT79637Author Commented:
Thanks experts!

My Firefox settings backup works.  I took advice from all three posts:
1. use full path names before "command".
2. added env variable PATH to script.
3. removed the "wild card" character from the file name.
4. added package mailx and can check my mail for success/failure.
5. added my own log to track success or failure by testing $? and outputing the return variable to a file and naming it appropriately.

I know this is a bit over kill, but it was a good exercise.

Thanks much!!!

/bin/mv /bkup/FEBE/profile{default}.fbu  /bkup/FEBE/daily/profile{default}.fbu-$(date +"%Y.%m.%d-%H.%M.%S")
if [ $? -eq 0 ];
then
    echo $? > /home/user/software/scripts/status.txt
    /bin/mv  status.txt /home/user/software/scripts/log/success.txt-$(date +"%Y.%m.%d-%H.%M.%S")
else
    echo $? > /home/user/software/scripts/status.txt
    /bin/mv  status.txt /home/user/software/scripts/log/failure.txt-$(date +"%Y.%m.%d-%H.%M.%S")
fi

Open in new window

0
 
IT79637Author Commented:
Thanks again.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now