I have cron entry that looks like this which works: (passing in 5 inputs)
30 10 * * 5 sh /home/test.sh hostnm101.abc /mypath/dir test foobar F008AR >> /logs/mytst.log 2>&1
I want to change it so I store inputs (4,5) foobar and F008AR in a separate file and read in by
script test.sh ($4,$5)
test.sh
#!/bin/bash
if [ $# != 5 ]; then
exit 1
fi
DIRDT=`date '+%Y%m%d'`
TSTDIR=$2/test/$DIRDATE
[ ! -d "$TSTDIR" ] && ( mkdir "$TSTDIR" || { echo 'mkdir command failed'; exit 1; } )
perl /home/dev/tstextr.pl -n $1 -b $2 -d $TSTDIR/ -s $3 -u $4 -p $5 -f $DIRDT
Is there any easy way to do this within the cron for those (2) input values? Thanks.
Alright try this way.
1) Create a separate file
/mypath/dir/login.infowith content like this (username/password in separate lines):2) Modify your test.sh like this:
3) Have your cron command like this:
Summary
I am using it like this:
Which means make new line character as field separator (since we are storing username and password in 2 separate lines). And then this line to read file
/mypath/dir/login.infointo an array:$arr[0]$arr[1]You can echo it to check read content: