cron shell script question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cron shell script question
# 1  
Old 03-30-2012
cron shell script question

Hi all, hopefully someone out there can give me some tips on how to resolve this

I have a simple shell script
Code:
 
who -u > /tmp/userlog


one of the line stored in userlog when executing shell script manually:

jim123 pts/24 2012-03-30 13:02 00:56 4131 (xya.dsfgds.com)

one of the line stored in userlog when execute the shell script as cron job:

jim123 pts/24 Mar 30 13:02 00:58 4131 (xya.dsfgds.com)



I'm not sure why the date formatting is different executing manually and as cron job but I need the date format to remain unchanged as 2012-03-30 when run as cron job.

any idea is much appreciated.

cheers,

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 03-30-2012 at 09:52 AM..
# 2  
Old 03-30-2012
Likely your login environment is setting LC_TIME (whereas cron will not be running .login/.profile).
This User Gave Thanks to CarloM For This Post:
# 3  
Old 03-30-2012
Thanks for the response CarloM.


I guess alternative is for below line:

jim123 pts/24 Mar 30 13:02 00:58 4131 (xya.dsfgds.com)

how to grab just 00:58 ? I tried using awk { print $6 } but for some reason sometimes it grabs 13:02 and other times it grabs 4131
# 4  
Old 03-30-2012
It might be easier to set LC_TIME in the cron script.

Your awk results are different because "Mar 30" is 2 (whitespace-separated) fields, but "2012-03-30" is only 1.
# 5  
Old 04-03-2012
Found a solution for this, there is probably better ways to fix this but if anyone is interested, add below to your cron file and the date format will stay the same for cron job.

Code:

LC_TIME="en_US.UTF-8"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Shell Script and Cron

How can I tell a script to only execute if the other scripts exits successfully? So "script A" executes and if it executes successfully (0),then "script B" will run or else "script A "executes and it exits unsucessfully (1) then "script B" will read return code (1) and will not execute ... (3 Replies)
Discussion started by: metallica1973
3 Replies

2. Shell Programming and Scripting

Shell script for cron url

Hi guys, I have a serious issue with running cron command. My host not supported format below mentioned, just the URL.) http://www.mysite/example.php ( I’m affraid a bit, the host do not going to support the sh as well…anyway) Somehow I need to „wrap” this command, to able to call cron: ... (1 Reply)
Discussion started by: vazzeg
1 Replies

3. Shell Programming and Scripting

Shell script and Cron

Hi there, I have a script that pulls in a weather feed via FTP then writes the output to a file. This script is run everyday at 3pm by cron. Heres the shell script: #!/bin/sh HOST='ftp.weatheronline.co.uk' USER='my username' PASSWD='my password'... (2 Replies)
Discussion started by: mpk_3
2 Replies

4. Shell Programming and Scripting

Shell script not working in cron

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 #!/bin/sh LOGFILE=/home/transfield/mou/test.log # Find yesterday Date and copy files TODAY=$(date --date= +%F) YESTERDAY=$(date... (4 Replies)
Discussion started by: malikp
4 Replies

5. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

6. Shell Programming and Scripting

Cron execution of shell script

Hi Guys, Unable to run this script from the cron,although the same executes perfectly from the command line.Please help. #!/bin/sh #### aprintd alarm creation files ##### file=`date +%m%d%Y` pid=$$ echo "$pid" /u01/app/netboss/bin/aprintd/aprintd > $file & childpid=$!... (3 Replies)
Discussion started by: ashish.sharma
3 Replies

7. UNIX for Dummies Questions & Answers

Running a script in cron question

There is this script I'd like to put into cron, but it asks for date verification. It'll prompt you to press enter to continue. Usually, 100% of the time the dates are ok, so is there a way to run this script in cron and bypass the "enter" prompt? (3 Replies)
Discussion started by: NycUnxer
3 Replies

8. AIX

Is it possible to have more than one Cron in shell script?

Hi, can we have more than one cron in the shell script? If so pls let me know on what basis it is running. Whether on OS scheduling or the time scheduled in the cron file.Pls answer this query. Many Thanks (4 Replies)
Discussion started by: Yamini Thoppen
4 Replies

9. HP-UX

executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different. Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK. There are echos in the shell script and... (2 Replies)
Discussion started by: abNORMal
2 Replies

10. Shell Programming and Scripting

Cron Script Question

A co-worker is having trouble w/ a job scheduled from cron and I got involved. Unfortunately I couldn't seem to find the answer and need some help. First off, I'm pretty sure he's using redhat linux. Anyway, I want to schedule a cronjob to run a java class. Let's say that, logged in as root, I... (3 Replies)
Discussion started by: doublek321
3 Replies
Login or Register to Ask a Question