Ubuntu :: Cron Runs Shell Script - But Only First Line Of It?
May 18, 2010
I have a cron job that runs a shell script. But it only runs the first line of that shell script and not the rest of the file. I'm a little stumped as to why. If I run the shell script manually, it runs and executes every single line as it should. I think I must need some additional syntax to make this run correctly?
Here is the crontab ...
Code:
root@kchlinux:~/macs# crontab -l
# m h dom mon dow command
I have an Ubuntu server running Couch Potato, Sick Beard and Sabnzbdplus. Everything "works" pretty well in a sense that CP and SB push the NZB's to Sabnzbdplus, but Sab crashes regularly (haven't found the solution or the cause for this problem, so if you have some advice regarding that, it's welcome).To counter this problem (Sab crashing) I have a script written which checks if Sab is runnning and if it isn't start it:
I have a script that is basically a series of rsync commands called bkup_all.sh. This script is located in the /root/ dir.From the command line (su'd as root), I can run the script like this:/root/bkup_all.sh > /var/log/bkup/bkup_$(date +%Y%m%d).logThis excecutes perfectly, and all the rsync adn script output is saved in a log file in the intended destination. However, I want this command to run automatically, so again, su'd as root I enter:crontab -ethen enter the following:00 02 * * * /root/bkup_all.sh > /var/log/bkup/bkup_$(date +%Y%m%d).logI want the script to run each night at 2:00am.But, the script does not run. There is no log file generated and I do not see anything in the syslog or system messages to indicate an error.
I have a cron job that I'm running once per minute.don't want to have the /var/log/crond.log get updated 60 times per hour. How can I suppress the logging of the job?I've tried adding the following to the cron line but they just get logged right along with it!
The problem is I need the php program to send member email confirmation which contains a confirm link. Run every min may still make the member wait. So I like to make it to run every 20 or 30 secs.
I don't want to put the code to send email on my sign up page as that's no good.
But I don't want to put a sleep 30 sec on my php script and going on loop. If it failed in the middle then it may wait abit to start.
What can be done to achieve my goal and what's the best way?
Making a php script to run as a daemon process? Is that possible and okay?
I am trying to write as bash script in order to have backup done by cron on the webhosting server. I want all backup runs to have incremental number in front of them. I came up with an idea to store incremental number of a backup in txt file on a server so when next one runs is can check the number in the file. However I am having terrible issues. My script:
Within a VMWare ESX virtual machine, I am running CentOS 5.2. (Actually, it is kind of a virtual appliance to run CollabNet's Teamforge - which I have installed for a trial). I've been dabling with Linux for a year or so, but I know I have much to learn.
I'm attempting to run a cron job that runs a backup script at 11pm. It works great, but unfortunately it runs at 11:30 am.
I created the cron job using 'crontab -e', while logged in as root. My cron job line is : 0 23 * * 1,2,3,4,5 /etc/tjt_backup/collabnet_backup.sh
If I type 'date', I get the correct date/time in my timezone: Tue Mar 9 16:27:12 CST 2010
If I type 'clock', I also get the correct date/time: Tue 09 Mar 2010 04:26:57 PM CST -0.463330 seconds
I am trying to execute an awk script which is called by a shell script. The result is that it always responds with << ^ invalid char ' ' in expression >>
As I do not have command line access, I use a php script as go-around.
On the command line,
Code: awk --version gives the following output: Code: Command: awk --version GNU Awk 3.1.3
I have a script that I would like to run using 'cron'. I want to use 'scp' to transfer files from one machine to another. I have set up the SSH keys on both machines. When I run the script from bash terminal, it works flawlessly. But when I schedule a 'cron' job to run the same script, 'scp' does not transfer the files.
'Return value' is 0 when the script is run from bash directly. But when it runs from 'cron', the 'Return value' is 1. That means, surely, that 'scp' is throwing an error. I don't know which error is being encountered. Could anybody let me know how to make it work?
I have just a one line script that runs telnet, and even thoughI've looked around I thought maybe someone could just tell me if there is a way to automatically login to the telnet server without having to type it in everytime. It's more of a hassle type of thing, but no matter what I've tried, I can't get anything to work.
I'm creating a script all worked fine in the command line. But not work in the cron. Below you could see the script
[Code]...
So far I found when I use corn following part not working, nothing goes to the processedfiles file. ls -l /var/lct/mou2/processed | grep $TODAY | awk '{print " " $8}' > /home/trans/mou/processedfiles ls -l /var/lct/mou2/processed | grep $YESTERDAY | awk '{print " " $8}' >> /home/trans/mou/processedfiles This work perfect in command line. Corn job and command line use by the same user.
Setup: 10.04 server with "bash" as /bin/sh When I run "ls -l" in a shell I get the following format:
Code: -rw-r----- 1 syslog adm 0 2010-06-13 06:53 /var/log/user.log Whereas if "ls -l" executes from a cron job the format is:
Code: -rw-r----- 1 syslog adm 0 Jun 13 06:53 /var/log/user.log Notice the different time format. Now I could fix this by changing the cron job to
Code: ls -l --time-style=+%Y-%m-%d %H:%M ... but I'm interested in knowing why this behavior occurs. What's different between the cron job and the shell?
I want to create a shell script that I can run as a cron job to do automated backups. how to proceed. I have the source code and have pulled out the backup source files. Here is the link for the source code. The download is at the bottom of this page. The backup files can be found in the src folder listed as backup.cpp and backup.h [URL]
If someone can do this, I believe it will make a nice addition to the Basket application for all.
Also I am not running Kubuntu I am running Karmic 9.10 64 bit
I've been having a bit of trouble running a shell script with cron. A friend of mine does a community radio show and the station has a live stream but no podcasts, so I've set up a script to record the stream and encode it as an mp3 while I'm away using mplayer and lame -that's what I'm trying to do anyway.
Here's the script, but it doesn't seem to run- at least, I don't see any of the files it should be outputing, would they be in the cron.weekly directory (where I have the script) or in my home directory?
#This is a script to record 'The Unnamed Show'
#it will record the show from the live stream, then convert the output #to an MP3
#Finally, it will delete any files no longer required HOME=/home/byron/
Im having some difficulties with running a shell script from cron which I am unable to resolve for almost 2 days now.
For testing purposes, im trying this with simple shell script test.sh with chmod 777
This script is located at /var When I type /var/test.sh it runs perfectly and prints asdasdasd When I type /var/test.sh > /home/log it writes asdasdasd to /home/log - works
The problem occurs whenever I add it as a cron job to var/spool/cron/crontab/root
There is: 11 10 * * * /var/test.sh > /home/log - however, at 10:11 there is no file at /home/log
Cron as a service works, forexample, every day at 4 am it makes this backup sshpass -p xxxx rsync -avz -e ssh root@x.x.10.7:/data/backup/ /home/backups/isp_admin
I am using Shell Script to run my Java program. I have written a Cron job to invoke Shell Script every day at 7pm. Cron job is running every day at 7pm ,but it is not invoking my shellscript and also I am not getting any error message. I am able to run same shell script from cmd propmt using bash, and also I am able to invoke the same script from mainframes Universal command job. Same ShellScript and Same cronjob is working fine in my Dev server. But in my QA server it is not working.
I have the following shell: export PATH=/u01/app/oracle/product/10.2.0/db_2/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin ftp -u -v -n -i > /bk01/exports/FTP_OUTPUT.LOG <<EOF open 197.0.0.78 user orabackup orabackup cd /media/disco/BK_Oracle bin put FILE00001.LOG put FILE00001.DMP quit EOF
Executing the shell from command line, the output is: Connected to 197.0.0.78. 220 Bienvenido al servicio FTP del servidor backup. 530 Please login with USER and PASS. 530 Please login with USER and PASS. 331 Please specify the password. 230 Login successful. 250 Directory successfully changed. 200 Switching to Binary mode. local: EXPO_APOT10G_20100531.LOG remote: EXPO_APOT10G_20100531.LOG 227 Entering Passive Mode (197,0,0,78,200,162) 150 Ok to send data. 226 File receive OK. 127498 bytes sent in 0.0022 seconds (5.7e+04 Kbytes/s) local: EXPO_APOT10G_20100531.DMP remote: EXPO_APOT10G_20100531.DMP 227 Entering Passive Mode (197,0,0,78,175,141) 150 Ok to send data. 226 File receive OK. 458190848 bytes sent in 6.1 seconds (7.3e+04 Kbytes/s) 221 Goodbye.
Executing the shell from cron, the output is: Connected to 197.0.0.78 (197.0.0.7. 220 Bienvenido al servicio FTP del servidor backup. 331 Please specify the password. 230 Login successful. 250 Directory successfully changed. 200 Switching to Binary mode. local: EXPO_APOT10G_20100531.LOG remote: EXPO_APOT10G_20100531.LOG local: EXPO_APOT10G_20100531.DMP remote: EXPO_APOT10G_20100531.DMP 221 Goodbye.
Why from cron the output no show the statistics in red ...?
I wrote a simple shell script called main.sh and inside it calling another shell script called rename.sh.Both are placed in a same directory.[/home/srimal/test]
My .jar file needs and uses some files in the same directory it's in (everything, including the jar was unzipped into said directory). It runs perfectly when I do java -jar file.jar in the command line, but there's trouble when I double-click the file when running from the file system manager. I've tried a custom command under properties ie java -jar, but the problem is that the .jar file doesn't seem to be able to use any of the files in the same directory. When running, the jar can't find any of the files that it needs.
I am a bit confused with the first line while writing a shell script , if someone can please explain me the meaning of the first line " #!/bin/bash "the confusion for me is the # at the beginning , in shell scripting # means a comment. but in this case it loads the shell which the script must use,instead of commenting the line how is this possible. where is this defined , any particular file.
I'm trying to create a super simple shell script, but I cant get a return line. The shell script looks like this (only the part that matters) Code: yes '' | ssh-keygen The idea being it will put in a blank char. Then enter until the program finishes. The problem is, it only does the first time, the next 2 times I have to hit enter, it requires me to input it manually (which is exactly what I'm trying to avoid).
The full script (if you care): Code: #!/bin/sh # Created by Omega # First, program creates RSA key, named id_rsa and id_rsa.pub # Second, program send the public code to requsted server. echo 'Removing old id_rsa key (if applicable)' rm -rf ~/.ssh/id_rsa.pub rm -rf ~/.ssh/id_rsa echo "Creating RSA key" yes '' | ssh-keygen
# Checking if ssh-kkeygen created requested file if [ -e ~/.ssh/id_rsa.pub ] then echo 'Done' echo 'Username and Server in: me@server format' read var1 echo 'Port Number? If standard put 22' read var2 ssh-copy-id -i ~/.ssh/id_rsa.pub "-p $var2 $var" else echo '' echo 'ERROR, ssh-keygen did not execute correctly' echo 'Retrying...' echo '' echo 'Please leave all options default (just press enter)' ssh-keygen if [ -e ~/.ssh/id_rsa.pub ] then echo 'Done' echo 'Username and Server in: me@server format' read var1 echo 'Port Number? If standard put 22' read var2 ssh-copy-id -i ~/.ssh/id_rsa.pub "-p $var2 $var1" else echo 'ERROR, ssh-keygen did not execute correctly' echo 'Quitting' exit fi fi # End