FedoraForum.org - Fedora Support Forums and Community
Results 1 to 7 of 7
  1. #1
    leaonow Guest

    weird cron job issue

    hi guys
    i wrote a piece of code to back up my wiki data file from fedora to my windows xp
    Code:
    #!/bin/bash
    working_directory=/root/scripts/cron
    source=/root/wiki/
    target=wiki.`date '+%y%m%d'`.tar
    remoteadd=//192.168.198.1/r
    mountpoint=/root/Rmount/
    winuser=administrator
    mypasswd=password
    log=/root/scripts/cron/backupwiki.log
    mount_error=1
    copy_error=2
    mount_flag=0
    copy_flag=0
    cd $working_directory
    echo "Hello-------------------------------------------`date '+%y%m%d'`">>$log
    mount.cifs $remoteadd $mountpoint -o user=$winuser%$mypasswd>>$log
    mount_flag=`echo $?`
    echo "$mount_flag">>$log
    if [ $mount_flag -eq 0 ];then
      echo "Mount successfully"
    else
       tail -2 backupwiki.log
       echo "bad mount">>$log
    
     echo "BadBye------------------------------------------`date '+%y%m%d'`">>$log
       exit $mount_error
    fi
    tar -czvf $target $source&&cp $target $mountpoint
    copy_flag=`echo $?`
    if [ $copy_flag -eq 0 ];then
      rm -rf $target>>$log
      umount $mountpoint>>$log
      echo "Backup successfully"
      echo "GoodBye-----------------------------------------`date '+%y%m%d'`">>$log
      exit 0
    else
      umount $mountpoint>>$log
      rm -rf $target>>$log
      echo "Copy problem"
      echo "Copy problem">>$log
      echo "BadBye------------------------------------------`date '+%y%m%d'`">>$log
      exit $copy_error
    fi
    this script works perfectly if i run it manually
    but it failed if run by cron job (as root user)
    Code:
    [root@MYSERVER cron]# crontab -l
    00 */1 * * * rdate -s time-b.nist.gov
    37 13 * * * sh  /root/scripts/cron/backupwiki.sh

    the error log is following

    Code:
    Hello-------------------------------------------080907
    127
    bad mount
    BadBye------------------------------------------080907

    the file structure is
    Code:
    [root@MYSERVER cron]# ls -l
     8
    -rwxrwxrwx 1 root root  236 09-07 13:37 backupwiki.log
    -rwxrwxrwx 1 root root 1199 09-07 13:00 backupwiki.sh
    anyone has any idea about error code 127 for mount.cifs?

    i spend couple of hours to figure out but just have no clue at all.......
    plz give a hand on this

    thanks and regard

  2. #2
    Join Date
    Jun 2006
    Location
    Texas
    Age
    55
    Posts
    4,164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't use cronjob, I put my scripts in /etc/cron.daily

    Check my sig for scripts, works well for me.

  3. #3
    leaonow Guest
    hey marcrblevins, thanks for ur quick response, well i am not able to access ur site,
    and the key thing here is, i need to know the same script
    why works perfectly if run manually
    but give error under a cron job

    cheers

  4. #4
    Join Date
    Jun 2006
    Location
    Texas
    Age
    55
    Posts
    4,164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put in the full path of mount, umount, & tar in your script. That is a wild guess.
    If you use mount.cifs, got to use umount.cifs as well, not umount.

    Use these
    Code:
    /sbin/mount.cifs
    /bin/tar
    /sbin/umount.cifs

  5. #5
    leaonow Guest
    u r the man,marcrblevins
    thanks alot dude
    one question following is
    the path for root(take it from /root/.bash_profile)

    PATH=$PATH:$HOME/bin:$ANT_HOME/bin:$JAVA_HOME/bin:$J2EE_HOME/bin:$JBOSS_HOME/bin
    :/sbin/

    why the script not able to fetch the /mount.cifs since i already include it /sbin/ in the path.....

    thanks in advance

  6. #6
    Join Date
    Jun 2006
    Location
    Texas
    Age
    55
    Posts
    4,164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found this link:
    http://linuxgazette.net/151/prestia.html

    Copy/Pasted from the link:
    PATH
    Because cron runs as subshell process, we need to either specify a path or use a PATH statement in crontab. The reason for this is that we are not logging into a console when we run these jobs - so neither .bashrc or .bash_profile have been sourced, and we have no environment variables to work with as we do when we login as a regular user or as root. It's also important to remember that trying to output data without a console is pointless - there's no screen to display it on! - so you need to make sure that any output that you want to save is logged somewhere.

  7. #7
    leaonow Guest
    cool mate, it's really helpful
    the reason i print to console is for debugging

    yeah,the problem is resolved,thanks again marcrblevins

Similar Threads

  1. Weird CD Issue
    By dmbrown00 in forum Hardware
    Replies: 0
    Last Post: 14th January 2008, 05:34 PM
  2. Weird issue
    By CPrgmSwR2 in forum Installation, Upgrades and Live Media
    Replies: 5
    Last Post: 24th March 2007, 11:05 PM
  3. weird RPM issue
    By teotihuacano in forum Using Fedora
    Replies: 2
    Last Post: 11th April 2006, 12:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •