Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-19
4
Medium Priority
?
552 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
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1200 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 200 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 600 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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
Suggested Courses

916 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