problems with changing date through shell script
am 05.11.2007 12:42:01 von vivek.j.joshiHello Friends,
I am trying to change the system date through a shell script. The
scrpt is very simple and works through the plain command. But it
doesnot work through the shell script.
It gives the following output:-
joshi@home-comp> sh changeDate.sh '$(/bin/date +0812)$(/bin/date +%H
%M)2007'
Changing the system date to $(/bin/date +0812)$(/bin/date +%H%M)2007
/usr/bin/sudo /bin/date $(/bin/date +0812)$(/bin/date +%H%M)2007
/bin/date: invalid date `$(/bin/date +0812)$(/bin/date +%H%M)2007'
I can't know what is going wrong. If I hardcode the command in the
script, it works:-
/usr/bin/sudo /bin/date $(/bin/date +0712)$(/bin/date +1530)2007
Can you please provide some insight on this thing?
Thank you all for reading this post
The actual script is:-
#!/bin/sh
# Make the sudo wrapper for /bin/date command to change date and time.
# Actual Command:-
# /usr/bin/sudo /bin/date $(/bin/date +0712)$(/bin/date +1530)2007
dateToBeChanged=$1
if [ -n "$dateToBeChanged" ]
then
echo "Changing the system date to $dateToBeChanged"
#echo "/bin/date $dateToBeChanged"
#/bin/date "$dateToBeChanged"
echo "/usr/bin/sudo /bin/date $dateToBeChanged"
/usr/bin/sudo /bin/date "$dateToBeChanged"
else
echo "Error: non empty argument."
echo "Usage: changeSystemDate [date]"
exit 1
fi
exit 0