Solved

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

Posted on 2010-09-19
4
518 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 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now