Solved

how to put the command-line parameters in cron in Red-head Linux

Posted on 2010-09-19
4
528 Views
Last Modified: 2013-12-21
Would like to input some command-line parameters with cron on Linux (Red head).
Here is the test code:

test.sh
#! /bin/ksh
if [[ $# != 3 ]]; then
  echo "Wrong inputs"
  exit 0
fi

if [[ "$3" == "v" ]]; then
echo "$1 $2"
elif [[ "$3" == "tst" ]]; then
echo "$1 $2 $3"
else
 echo "Wrong info"
fi

If it is run in command-line prompt, it gets the right result:
/u02/test.sh Hello World tst > /tmp/test.log

In test.log
Hello World tst

However,
32 13 * * * /u02f/test.sh Hello World tst > /tmp/test.log 2 >&1

It gave in test.log

Wrong inputs

Gurus, please help.
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 300 total points
ID: 33712107
Hi,

the script worked on the command line because you didn't add the last (erroneous) part (2 >&1) there!

You must remove the space between "2" and ">&1"
else the "2" will be considered a parameter by the shell, raising $# to "4"

32 13 * * * /u02f/test.sh Hello World tst >/tmp/test.log 2>&1

It's also good practice (although not mandatory) not to leave a space between ">" and the following path.

That's all.



0
 
LVL 11

Assisted Solution

by:jgiordano
jgiordano earned 50 total points
ID: 33712110
if this is the exact cron entry then you have a typo in the file path; there is an f in your cron path and non in the first example.

32 13 * * * /u02f/test.sh Hello World tst


/u02/test.sh Hello World tst > /tmp/test.log
0
 
LVL 6

Assisted Solution

by:jghelfman40
jghelfman40 earned 150 total points
ID: 33735034
You may want to put your command in parantheticals, as you are then guaranteed that it will be interpreted as one command.
In addition to this you can run it against 'atd' as a test. If your atd isn't running it should be a startup script under /etc/init.d/

at now +1
> /u02f/test.sh Hello World tst >/tmp/test.log 2>&1

If this works then add it to cron:
32 13 * * * ( u02f/test.sh Hello World tst >/tmp/test.log 2>&1 )
0
 

Author Closing Comment

by:jl66
ID: 33784352
Thank each of you very much. It works. Sorry for delay.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Utilizing an array to gracefully append to a list of EmailAddresses
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question