Hello,
I know little about shell scripting and creating a script, and worked fine in the command line. But not work in the cron. Below you could see the script
This is a topic which very often comes up. Starting something on the command line is not the same environment like when started via cron. Environment variables will not be set like PATH and so on.
You can either use the search function of the forum and/or read this: https://www.unix.com/answers-frequent...n-crontab.html
Please post the exact cron line and state when you expect the cron to run.
Please state which Operating System you have.
Remember that the script will need to be invoked with the full path name of the script (not as ./scriptname).
If the cron is failing for some reason the error messages will be in mail for the cron user (e.g. root). Also check that the cron runs at all by looking at the logfile for your cron (see "man cron" to find the name of the logfile). How did you add the job to the crontab?
I'm using Ubuntu 9.10 server 64 bit.
I changed the location of the script to simplify the test
so far I try following cron lines and syslog show script executed but nothing goes to the processedfiles
49 08 * * * /home/malik/test/Tmoustart
02 09 * * * sh /home/malik/test/Tmoustar
I add . $HOME/.profile to pick-up the environment variables. Hope that's the correct way.
---------- Post updated at 11:18 AM ---------- Previous update was at 09:05 AM ----------
Now I narrow it down to grep command
I use following simple script
Code:
#!/bin/bash
ls -l /home/malik/test
echo "1 done ###"
ls -l /home/malik/test | grep 2010-01-22
Output from command line
Code:
malik@sysdb:~/test$ ./greptest
total 12
-rwxr-xr-x 1 malik malik 97 2010-01-22 11:04 greptest
-rw-r--r-- 1 malik malik 0 2010-01-22 10:28 processedfiles
-rw-r--r-- 1 malik malik 2501 2010-01-22 10:55 test.log
-rwxr-xr-x 1 malik malik 715 2010-01-22 10:54 Tmoustart
1 done ###
-rwxr-xr-x 1 malik malik 97 2010-01-22 11:04 greptest
-rw-r--r-- 1 malik malik 0 2010-01-22 10:28 processedfiles
-rw-r--r-- 1 malik malik 2501 2010-01-22 10:55 test.log
-rwxr-xr-x 1 malik malik 715 2010-01-22 10:54 Tmoustar
Output from cron
Code:
total 12
-rwxr-xr-x 1 malik malik 715 Jan 22 10:54 Tmoustart
-rwxr-xr-x 1 malik malik 94 Jan 22 11:13 greptest
-rw-r--r-- 1 malik malik 0 Jan 22 10:28 processedfiles
-rw-r--r-- 1 malik malik 2501 Jan 22 10:55 test.log
1 done ###
For some reason grep not working. I tested in three computers with Ubuntu 64 bit and 32 bit.
Any body know any other way I could do this?
Thank you,
---------- Post updated at 02:31 PM ---------- Previous update was at 11:18 AM ----------
Hello all I mange to fix the problem using find command. But still I do not know why grep failed. I found grep failed with any number. if I use characters work fine.
Basically I used the script to find last 3 days files in a folder and copy to another location.
using find command as below I mange to do the same and also that make my script smaller too
find /var/lct/mou2/processed/ -mtime -2 > /home/trans/mou/processedfiles
The problem I see is that the date format in $TODAY and $YESTERDAY does not match the date format in your "ls" from cron. Maybe you have an alias for "ls" in the user acount which produces the non-standard date format?
In general the match string for grep should be in double quotes.
As you have deduced it is better to use "find" in this circumstance anyway.
Hi,
I have written a shell script to list all the files with some pattern as below.
<CODE> ls *_20151201*.txt <CODE>
its working properly when ran manually. But when i tried to run by cronning it.. its throwing an error that no files exists with file name *_20151201*.txt
But when I try... (3 Replies)
Hi all,
I have script, which performing sql queries and put output into file.
When I run this script manually, its working fine, but when I want to schedule it with cron I am getting errors...
I defined LD_LYBRARY_PATH and ,but no result. After I defined it, I am getting error:
# more... (4 Replies)
Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered.
The script is as follow:
#!/bin/sh
for file in file_1.txt file_2.txt file_3.txt
do
awk '{ print "0" }' $file > tmp.tmp
mv tmp.tmp $file
done
And the cron... (2 Replies)
Hi
I have written an email script in python which sends email to the given id.
I have customized the script for generating space alert inside a shell script as shown below
df -h /microfocus > /tmp/spacereport
## Filter the %usage to variable per
per=$(awk '{if (NR==3){print $4}}'... (0 Replies)
Hello,
I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me
1) How could I check my script when it is running from cron like... (3 Replies)
Hi @ all :)
i made a very little shell script witch is working well when i'm launching it directly
like with ./script
but when i'm launching it by cron tab it work at half only.
the part of the script witch are not working are:
#!/bin/sh
apt-get updade
apt-get -s upgrade >>... (5 Replies)
Hello,
I have the following script which works fine when ran from the command line:
#!/apps/python/2.3.4/bin/python
import os
import sys
import time
user = os.getenv("USER")
string = time.strftime("%m%d%y0000 " + user, time.gmtime())
However, when I have this run by crontab, I... (4 Replies)
Hi All,
i have a cron entry like
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /amex/sssmonitor/dss_chk.ksh
and the script is like
#!/bin/ksh
file=`uname -n`
> /sunmast/projects/oasis/COREDEV/Dss$file.log
> /tmp/output_sss
today=`date`
varb=`ps -ef | grep... (5 Replies)
I ran an ssh command to run a script on a remote server
ssh -l <user> <servername> /path/to/script/scriptname
This works fine - and the script is executed correctly.
However - I put this command into a script, that I want to run from cron every hour, to execute the file on the remote... (31 Replies)
guys
i have written a very simple script .it runs manually well.
but when i put it in cron,it doesn't give the desired output.
script looks like this:
#! /usr/bin/sh
#script for loading data in table using ctl file/Abhijeet K/08.07.2006
/svm_wl1/. .profile
cd... (5 Replies)