???? how to launch bash script in cron ????

with help from people in this forum, I successfully debugged the syntax in a shell script I wrote (my syntactical faux pas had to do with sending a multi-line mail message from a bash script).
I can manually launch my script from Terminal's command line, and it works perfectly (well, at least it does exactly what I told it to do:). I try to launch it via cron, and it doesn't appear to ever launch.
In /var/cron/tabs/root, the pertinent line of text reads:
00 22 * * * /usr/local/customShellScripts/script.sh
so it is supposed to launch daily at 10PM.
Other jobs listed in /var/cron/tabs/root do run, because I get emails to my postfix admin account saying that they do. However, none of those other jobs are shell scripts; they are stuff like:
24 06 * * 5 /usr/sbin/diskutil verifyVolume /
The directory listing for /var/cron/tabs/root reads:
$ ls /var/cron/tabs
total 4
drwxr-xr-x 3 root wheel 102 Mar 25 18:53:28 2006 .
drwxr-xr-x 3 root wheel 102 Mar 20 17:13:47 2005 ..
-rw-r--r-- 1 root wheel 1040 Mar 31 20:28:10 2006 root
The directory listing for script.sh reads:
$ ls /usr/local/customShellScripts/
total 24
drwxr-xr-x 6 root wheel 204 Mar 31 18:31:27 2006 .
drwxr-xr-x 11 root wheel 374 Mar 5 12:26:23 2006 ..
-rw-r--r-- 1 root wheel 6148 Feb 4 14:13:22 2006 .DS_Store
-rwxr-xr-x 1 root wheel 8058 Mar 31 20:27:50 2006 script.sh
for debug, the first two lines of script.sh read:
#!/bin/sh
/usr/bin/touch /foo
but the file /foo never gets created. I tried using just "touch /foo" and that didn't work either.
Also, since the script has a lot of calls to "echo," "expr," "date," "cut," "awk," etc., if I ever get cron to execute the script past the shebang line, do I have to preface all those calls with their full path? Or can I do something like in the old /etc/crontab file, where they defined a path variable up front
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
and the script will be smart enough to look in those directories for the appropriate executables?
But, getting back to the first problem, I am obviously overlooking something very basic, which is not surprising since I'm self-taught (and I guess, Apple Unix Discussions forum taught) at this unix thing and shell scripting. So, can anybody bail me out here...again?
2001 Quicksilver G4   Mac OS X (10.4.5)  

Hey Reese
You bailed me out, dude! Apparently, my difficulties stemmed from me trying to directly edit /var/cron/tabs/root with pico. Never seemed to bother the other stuff, but it did this time. I am totally inept with vi, the default editor for crontab -e, which is why I had cheated before, and directly edited the /var/cron/tabs/root, el.al., so I had to find out how to
export EDITOR='pico'
in my .bashrc
After having done that, no problem, except for a latent programming logic bug that has reared its ugly head (my script is doing some date manipulation with today's and yesterday's date, and my script crashed and burned on the month change and with stuff related to single-digit date sequence numbers <10).
But, hey, I learned how to reset my default editor, so as to make life easier for me when it comes time to dorking with crontab files, and I learned that when the crontab file says "DO NOT EDIT THIS FILE - edit the master and reinstall," it means it!
Thanx for the troubleshooting hint.

Similar Messages

  • How to run bash script using Calendar

    Hi folks.
    How can I run a bash script using Calendar?  I thought I had to park it in an AppleScript script which I could call, but that isn't really working.
    Any suggestions appreciated.
    Cheers

    Hi there.  Thanks for the reply.
    Some notes for the replies:
    - The shell script has no environment issues.  It's a straight mysqldump for a single database.
    - The AppleScript has the do shell script "path/to/script.sh" user name "root" password "wobblyhead" with administrator privileges
    - Calendar application can only recognize the .scptd and .scpt files, and not .app files.  Upon choosing my original .scpt file with the do shell script instruction, it just opens the file in AppleScript Editor. 
    So the file gets called, but for some reason, it just opens the file and won't run the file.  No options for choosing a format where it's actually run. 
    Not sure how to go about this. 
    Cheers

  • [SOLVED] How to get BASH scripts to recognize mounted partition paths?

    I don't understand how to get the bash script in the root partition to find the boot partition--both mounted at /mnt.
    I'm following the instructions on configuring "dm-crypt with LUKS" tutorial. The mkinitcpio command to generate the "initial ram disk environment" is producing an error while the system is booted from the install disk and the volumes it looks for are mounted at /mnt.
    #mkinitcpio -p linux
    ==> Building image from preset: /etc/mkinitcpio.d/linux/preset: 'default'
    -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
    ==> ERROR: specified kernel image does not exist: `/boot/vmlinuz-linux'
    ==> Building image from preset: /etc/mkinitcpio.d/linux/preset: 'fallback'
    -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect
    ==> ERROR: specified kernel image does not exist: `/boot/vmlinuz-linux`
    The script located in /mnt/root/etc can't find the "temporary kernel" located at /mnt/boot.
    Last edited by xtian (2013-09-17 22:01:35)

    And read them carefully, there should be no /mnt/root/etc/.
    There should be a /mnt/etc/ and a /mnt/boot and /mnt/root/ which is the root user's home directory, not the root filesystem (and of course /mnt/usr ...) - or if you decide to nest the whole thing deeper you could have /mnt/somename/etc and /mnt/somename/boot ...

  • Bash script with Cron job

    Hello,
    This is my first post:-)
    we have developed one script to do basic LDAP healthcheck and tested. It's working fine. But have to run manually daily. I want to put that script in cron job.
    So that it generates reports automatically. Can some one please give me the hit on it or any links which i could understand more easily.
    Thanks.

    Hi,
    this doesn't look exactly like a DS-related question, however the best option would be 'man crontab' / 'man cron' and read the man pages ;-)
    But, assuming you're running Solaris 10... and you would like to run your script every day of every month of every week at 1:30 AM... you should add the following line to your crontab:
    1 30 * * * /full/path/to/your/script.sh
    HTH,
    Marco

  • How to launch Calc Scripts from Analyzer

    Hello all,Just wondering if that there is an easier way to launch calcs from analyzer... what are some of the ideas -using a executable lauch button, hyperlink, via Analyzer API? Any other ideas appreciated. regards, Ray

    This message has resolved my query by setting a larger MAX_PROPERTY_VALUE_LENGTH to "30"Thanks.I have come across this problem before. If it is the same problem it is to do with the length of your calc scripts. Obviously Essbase calc scripts are stored as .csc files, if these are too big Analyzer can't read them. This issue is caused by the ADM layer that Analyzer uses. Search on the server for a file called adm.properties .You should find the file in the following directory \\hyperion\analyzer\adm\lib .You may find you have more than one copy on the Server in which case edit them all. In the file find a string called MAX_PROPERTY_VALUE_LENGTH. You will find this is currently to 4 (this respresents 4kb). Increase the value to say 20. Save changes, restart Analyzer Service and hopefully this should have fixed the problem. I would love to know if this works. Paul Armitage. Analitica Ltd. www.analitica.co.uk

  • Cron job : how to run scripts as cron job

    Hi friend,
    Sorry one very small question ..
    Can someone tell me how can i run scripts as cron job .. on HP UX.
    thanks
    ashish

    Hi Ashish,
    open one telnet session.
    crontab -e
    then give the periodicity day and time
    like below
    05 00 * * 1-6  /usr/local/bin/database_backup.sh
    and now create the script file with the command or script to execute.
    Regards
    Ashok Dalai

  • BASH Script - Launch App with

    I'm trying to write a simple BASH script that will laungh an program, but that program needs command line arguments.
    When I put it in quotes it says it can't find the file, if I don't use quotes then it won't run the program with the command line arguments. How can I launch a program using a BASH script with command line arguments?
    Thanks in advance

    #!/bin/bash
    /Users/name/Desktop/Directory/app -f configfile

  • /etc/rc.d/network: bash script: how to find out, if there was an error

    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy

    iggy wrote:
    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy
    try using netcfg to start the wireless profile, that should keep you happy until the new network scripts are unleashed... which won't have this problem.
    James

  • How can I execute a bash script by double clicking in finder

    Hello!
    How can I execute a bash script using finder? Or better: How can I create an alias, which executes my bash script?
    Thanks Johann

    Add the suffix command in your script name. E.g. Script.command.

  • How do I save a "bash" script? (in attempt to fix one of my other problems)

    Here is my original problem:
    http://discussions.apple.com/thread.jspa?threadID=2195627&tstart=0
    I came across this that sounds like it will help my issue:
    http://www.macosxhints.com/article.php?story=20090316190817357
    However, what am I supposed to do with that code? Put it in the Terminal? Save it as an Apple Script? I also got the "lingon" program set up, all I need to do is figure how how to save this "bash" script and all set!
    Any ideas?
    -Scott

    This link might help as it shows how to create the plist using lingon:
    http://mymacfixes.blogspot.com/2009/06/how-do-i-stop-clicking-noise-from-hard.ht ml

  • How to download file using ftp in bash script

    Hi! I'm runnig a bash script in solaris i want within the script to dowload file using ftp
    How can i do it?
    Tanks a lot

    hello,evgchech
    please try this way:
    1. In the bash script, try following command:
    ftp -n < ftpcmdfile2 in the ftpcmdfile (which is a file),coding the interactive commands of FTP such as:
    user anonymous  [email protected]
              cd /var/sun/download
              bi
              mget *.*
              bye
         try it and good luck!
    Wang Yu
    Developer Technical Support
    Sun Microsystems
    http://sun.com/developers/support

  • How to send 2 variable value from bash script into java.class

    #!/bin/bash
      a=10
      b=20
       echo $a $b | java addition
    donehi there,
    currently i have a simple java coding ( a + b ). and i m trying to connect with bash script but this bash script coudln't Enter 2nd value (b=20) while i running for it. may i know how do i can Enter 2 value into it?
    output from terminal
    [seng@localhost java_class]$ bash addition.sh
    =======================================================================
    simulation 1
    Num_a       = 10
    Num_b       = 20
    Enter your Num_a : 10
    Enter your Num_b : Exception in thread "main" java.lang.NumberFormatException
       at java.lang.Integer.parseInt(java.lang.String, int, boolean) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.Integer.parseInt(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
       at filter_god.GOD(java.util.List, java.util.List, java.lang.String, java.lang.String, int) (Unknown Source)
       at filter_god.main(java.lang.String[]) (Unknown Source)
       at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
       at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    =======================================================================

    That code will send both numbers on a single line in standard input to the java process. So if the process reads standard input, it will get a single line that has this in it: "10 20".
    I'm guessing you're sending that whole line to Integer.parseInt. But a valid number doesn't have a space in the middle.
    You should split up the line using String.split. Or use a StringTokenizer. Or a regular expression. Or you can use a java.util.Scanner. Or a java.io.StreamTokenizer. Or maybe some other stuff that has slipped my mind at the moment.

  • Bash script run via cron not executing MYSQL command

    I have a bash script which is run from a cron,
    It is executing as I have it write to a log file which it does correctly.
    I am wanting the bash script to restore a mysqldump file.
    When I run the bash script manually the dump file gets loaded fine. But when I run it through the cron the mysql command appears to be ignored.
    The mysqldump file is 54MB and I have checked to make sure that MYSQL is included in the global users path in /etc/profile
    Does anyone know why this maybe??
    Here is the bash file
    #!/bin/bash
    date >> /home/user/crons/crons.log
    echo "Started loadbackup" >> /home/user/crons/crons.log
    cd /home/user
    dbuser=root
    dbpass=password
    dbname=databasename
    filename=backup
    mysql -hlocalhost -u"$dbuser" -p"$dbpass" "$dbname" < " >> /home/user/crons/crons.log
    My crontab looks like
    02 17 * * * /home/user/crons/loadbackup.sh
    Many thanks
    Richard

    Hi Richard,
    Have you tried redirecting the script output in the cron to see if an error is being reported?
    I.e.
    02 17 * * * /home/user/crons/loadbackup.sh > /tmp/loadbackup.log 2>&1

  • How do I run a bash script *before* login?

    I've got a bash script that opens an SSH tunnel that I'd like to run (as root) before any user logs in. How do I go about getting this script to run between boot and user login?
    Thanks.

    Post Unix queries to the Unix forum under OS X Technologies where those mavens frolic.

  • Learning how to bash script, questions.

    Hello everyone,
    So I'm learning how to Bash script so I can improve my AUR packages, and also make some scripts for my personal use.
    I've been working on a basic script that completely cleans your kernel source tree while saving your config file.
    I was wondering if this is good and up to today's standards (Meaning checking existence of files, and checking return status for previous command):
    #!/bin/bash
    mv .config config
    if [ -e "config" ] ; then
    echo "Configuration has been backed up successfully."
    else
    echo "Error renaming, quitting program."
    exit
    fi
    echo "Cleaning your kernel source tree!"
    make distclean
    if [ $? -eq 0 ]; then
    echo "Your kernel source tree was clean successfully."
    else
    echo "Error cleaning your kernel source."
    fi
    mv config .config
    if [ -e ".config" ] ; then
    echo "Configuration has been installed successfully."
    else
    echo "Error renaming, quitting program."
    exit
    fi

    What happens if you accidentally run it in your home directory? You probably don't want to be moving your .config folder around like this, even if it doesn't get hurt. Also, what happens if there's a pre-existing "config" file or folder? You should probably inform the user to deal with it, and bail out.
    I would also consider using more verbosity, eg in the calls to "mv", and make the echo statements more descriptive and maybe use some colour.
    In summary, if it were me, a first draft before playing with it more might look a bit like this:
    #!/bin/bash
    set -e
    RED="\[\033[31m\]"
    GREEN="\[033[32m\]"
    BLUE="\[033[34m\]"
    RESET_COLOURS="\[\033[0m\]"
    CONFIG_FILE=".config"
    BACKUP_FILE="config"
    if [[ -f "$CONFIG_FILE" && ! -f "$BACKUP_FILE" ]]; then
    printf "Backing up existing configuration: $BLUE"
    mv -v "$CONFIG_FILE" "$BACKUP_FILE"
    printf "${RESET_COLOURS}\n"
    else
    echo "Existing configuration not found or backup already exists, nothing to do."
    exit
    fi
    printf "Cleaning kernel source tree in $(pwd) ... "
    make distclean
    if [ $? -eq 0 ]; then
    printf "${GREEN}Success!${RESET_COLOURS}\n"
    else
    printf "${RED}Failed!${RESET_COLOURS}\n"
    fi
    if [[ -f "$BACKUP_FILE" && ! -f "$CONFIG_FILE" ]] ; then
    printf "Restoring pre-existing configuration: $BLUE"
    mv -v "$BACKUP_FILE" "$CONFIG_FILE"
    printf "${RESET_COLOURS}\n"
    else
    echo "Backed up configuration not found or pre-existing configuration already there, nothing to do."
    exit
    fi
    Last edited by /dev/zero (2012-01-13 23:03:10)

Maybe you are looking for