Problems running script in cron...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems running script in cron...
# 1  
Old 10-06-2010
Problems running script in cron...

Hi all, I have a script running on a Solaris 8 box and the first thing it does it check which user is executing it;

Code:
if [ "$( /usr/xpg4/bin/id -un)" != "testuser" ]; then
   echo "This script must be run as testuser" 1>&2
   exit 1
fi

This works fine when manually running the script however when adding into that users' crontab it errors out within /var/mail/testuser saying;

Quote:
This script must be run as testuser
I'm guessing cron must assume the role of whatever crontab it is running, but can anyone explain why this hasn't worked and if there is a way around it?

Thanks Smilie
JayC89
# 2  
Old 10-06-2010
Hi.

I would start by replacing $( ... ) in your if statement with `...` (backquotes).

The cronjob will run in the default shell of the user who's cronjob it is. But it won't load your .profile, etc. so you might want to do that, either in the job definition, or in the script itself (assuming that is, that there is more to your script that we see here).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not running in cron

Hi All, I have a script which is running fine while triggered manually, However if I placed in crontab it throwing an error. #!/usr/bin/ksh set -vx lc=1 st_date=$(`date "+%Y%m%d"`) LOGFILE=/home/transfer.log.$st_date file="/home/OM_WF.log.$st_date" Manual run - lc=1 + lc=1... (4 Replies)
Discussion started by: nag_sathi
4 Replies

2. Shell Programming and Scripting

Script running using cron

Hello All, I am running the below script.when i am running from shell or terminal its running fine but running using cron its not working. ################################ b36376 27 % cat make_nis_account_ankit.sh #!/bin/ksh ... (2 Replies)
Discussion started by: ajaincv
2 Replies

3. Solaris

Script not running from cron

Hi, I''ve made a script that's running fine from the command line but when running from cron it encounters the following issue: /tmp/tstscript/testfail.ksh: typeset: not found I've searched in Google and couldn't find anything, here's the beggining of the script (I can post the rest if... (4 Replies)
Discussion started by: Cvg
4 Replies

4. UNIX for Dummies Questions & Answers

Problems with script and Cron

Hi Guys, total newbie here, Ive read through some of the threads about cron and scripts not working and have still drawn a blank as to why mine isnt working correctly. I have a script that runs the ausearch with a set of criteria i have setup, the only access i have to the system is via... (5 Replies)
Discussion started by: richie190784
5 Replies

5. Red Hat

Problems with script running with crontab

Hi, I'm trying the backup a few information commands of my Check Point FW (it's on a SPLAT linux machine). This is the script I wrote: #!/bin/bash cd /var/tmp/ file1=netstat_`/bin/date +%d%m%y`.txt file2=ifconfig_`/bin/date +%d%m%y`.txt file3=cpstatos_`/bin/date +%d%m%y`.txt... (2 Replies)
Discussion started by: nirsh
2 Replies

6. UNIX for Dummies Questions & Answers

Problems running a emcast from cron job

Hi, I have problem with running emcast from cron job (I use emcast because it supports multicasting). I have simple script that looks like this: emcast 234.5.6.1:1234 > file.ts Script is saved like stream.sh When I run it from shell, file is created and some data is written in it. When... (2 Replies)
Discussion started by: goldsmith
2 Replies

7. Shell Programming and Scripting

Running a script with cron

I have the following script (trapsize) that checks a file size on my syslog server, and if the file is gt 6g, it will mail an alert to the admin for inspection. The following works like a champ when I execute ./trapsize logged in as root user using bash shell. FILESIZE=$(ls -l /opt2/fwsm/fwsm... (3 Replies)
Discussion started by: altamaha
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Running Script from Telnet - Problems

...so I read "The Pragmatic Programmer" and they stressed the value of learning shell scripting! I'm in a UNIX environment but have a Windows XP workstation. I'm using Telnet to issue UNIX commands. I've done plenty of chmod's, command line ftp and stuff, but written no scripts to this point.... (1 Reply)
Discussion started by: pauljohn
1 Replies

10. Shell Programming and Scripting

Running script using cron

I am running a script by scheduling it using the cron. The line in the cron file is - 10 * * * * ksh -v /apps/gofis/svam/cos_automation/cos_automation.sh vpqa > /apps/gofis/svam/cos_automation/cron.log 2>&1 But after the job is executed, the cron.log contains some part from... (4 Replies)
Discussion started by: ankurgupta
4 Replies
Login or Register to Ask a Question