PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > problems with changing date through shell script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

problems with changing date through shell script

Réponse
 
LinkBack Outils de la discussion
Vieux 05/11/2007, 11h42   #1
wizard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut problems with changing date through shell script

Hello 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

  Réponse avec citation
Vieux 05/11/2007, 12h10   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: problems with changing date through shell script

wizard wrote:
> Hello 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'


Single quotes will take and pass that string literally to your script
and will not expand the $(...) expression. Use double quotes instead.

Janis

> 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
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10332 seconds with 10 queries