Visit Our UNIX and Linux User Community

Simple Bash Script - Crontab

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Bash Script - Crontab
# 1  
Old 10-01-2014
Simple Bash Script - Crontab

I've put together a very simple bash script to check for software patches and bounce the server, once complete. This is on a Mac server. The script works just fine upon execution, however, cron responds with:

/bin/sh: /usr/local/bin/ No such file or directory


#*      *     *    *     2,3,7    /usr/local/bin/

Here's my simple bash script:


#Checks and executes software updates & bounces server.

sudo softwareupdate -i -a

sudo reboot
The script lives in /usr/local/bin. It's obvious to me, environment is the issue. However, not sure the direction to resolve. Attempted a variety of options. Any assistance, is appreciated.
# 2  
Old 10-01-2014
What's the name of the script? Its permissions? Pls show the result of ls -l /usr/local/bin/soft*.
# 3  
Old 10-01-2014
Originally Posted by RudiC
What's the name of the script? Its permissions? Pls show the result of ls -l /usr/local/bin/soft*.
I made a simple mistake in crontab. I added an "s," to the name. It's singular, "" I've made the correction and now receive output:

/bin/sh: command not found

To add, it's in "roots" crontab. I execute from root, manually, with no issues.


-rwxr-xr-x@ 1 admin  staff  142 Oct  1 12:38 /usr/local/bin/

# 4  
Old 10-01-2014
There (shebang) might be carriage returns, try

tr -d '\r'  < /usr/local/bin/   > script_tmp
mv script_tmp /usr/local/bin/ && chmod +x /usr/local/bin/

# 5  
Old 10-01-2014
Resolved. Need to specify "softwareupdate" command, path.


#Checks and executes software updates & bounces server. 

sudo /usr/sbin/softwareupdate -i -a

sudo reboot

# 6  
Old 10-09-2014
When the cron job is owned by root, do you still need to use 'sudo'?

Puzzled. Smilie
# 7  
Old 10-09-2014
For a root crontab you don't need sudo.
But you should fix the execution time, otherwise it will update/reboot every minute!
For example
# update/reboot at noon
0  12     *    *     2,3,7    /usr/local/bin/

Previous Thread | Next Thread
Test Your Knowledge in Computers #330
Difficulty: Easy
The first dual-core CPU was the Intel Pentium D.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot get this bash/expect script to run under a crontab

#!/bin/bash # # RAP configuration script # # Usage: ./ # # Requires: expect, tcl # # Script expects to find a file called rap.csv located in the same directory as the script. If the file is placed # in a different directory, modify the custom entries section to specify the absolute... (8 Replies)
Discussion started by: mrkool
8 Replies

2. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

3. Shell Programming and Scripting

Crontab - wrote Simple Script but i cant work out how to play it at a certain time.

Hi everyone. Silly might be silly be I'm still new to bash. I'm trying to make an Alarm Clock for in the morning using my laptop i have wrote this Simple Script but i cant work out how to play it at a certain time. #!/bin/bash cd /home/josh/Music/Bruno_Mars/Hooligans/ cvlc... (8 Replies)
Discussion started by: jtsmith90
8 Replies

4. Shell Programming and Scripting

Simple bash script help

Hi to everyone here, I'm a new user and relatively-new linuxer. I'm trying to write a script that checks if every file from a directory is present in a given list and if not, delete it. should be simple. But I think I've done half the work only: this is to create the reference list: for c... (2 Replies)
Discussion started by: dentex
2 Replies

5. Shell Programming and Scripting

need a simple bash script

to gather the cpu utilization from a system in 5 minute intervals and direct output to file. I'm new at scripting and while this seems like an easy task I'm confused on where to start. thanks for any help (1 Reply)
Discussion started by: mkeyes001
1 Replies

6. Linux

Problem with crontab + bash script

Crontab: 16 14 * * * /root/bin/./ >> /root/bin/log.txt L=`mailq |grep -c frozen` echo "${NUMMAIL} frozen mail to be removed from the mailq" #echo "Press Enter to continue" #read CONTINUE echo -en "-> " for i in `mailq | grep frozen | awk '{print $3}'` ; do exim4 -Mrm $i... (1 Reply)
Discussion started by: wessberg
1 Replies

7. Shell Programming and Scripting

simple bash script

I am writing a shell script in bash one of the thing I want to show is size of export /home du -sk /export/home/oracle | cut -c 1-5 echo "kbytes" when I run the script kbytes shows up in the second line, How can I append kbytes on the same line, such as 61233 kbytes please guide thanks (2 Replies)
Discussion started by: Tirmazi
2 Replies

8. Shell Programming and Scripting

Simple BASH script?

Hi guys, I'm new to the forum so forgive me if I'm sounding ... daft. I currently work in a Tech Support role. Every day we have to generate data by running around 10 .sh scripts. I was thinking instead of having to ./filename 10 times is it possible to right a new script that will run these for... (16 Replies)
Discussion started by: JayC89
16 Replies

9. UNIX for Dummies Questions & Answers

how to execute sh script in bash shell via crontab

hello. we are porting over from HPUX Shell to Linux. my default shell is bash so i can no longer schedule to execute a sh script in crontab. can anyone pls help me out? I searched the site but didnt find any details. thanks! (1 Reply)
Discussion started by: jigarlakhani
1 Replies

10. Shell Programming and Scripting

Simple Bash Script

I'm sure I'm doing something wrong but as I am new to bash shell scripting I'm not sure what: Here's the code webalizer.conf is sitting in the same directory as this file which is named Can someone tell me if I've got the syntax right -- it that's correct? I'm executing the... (3 Replies)
Discussion started by: xaphalanx
3 Replies

Featured Tech Videos