0

I have to change the date after an SSH login into machine, but I am not able to change it. Here is the script I have written:

#!/bin/bash
ENVIRONMENT_LIST=environment_ip_list
USERNAME=root
declare ENVIRONMENT_ARRAY

mdate="$#"

readIp()
{
while read IP
    do
        ENVIRONMENT_ARRAY[$env_count]="$IP"
        let env_count++
    done < $ENVIRONMENT_LIST
}
change_date()
{
    for ((i = 0; i < env_count; i++))
    do
        ssh -t -t -o StrictHostKeyChecking=no $USERNAME@${ENVIRONMENT_ARRAY[i]} "'date -s "$1 $2 $3 $4"'"
    done
}
readIp
change_date

In a terminal, I get this output:

~/Desktop/changedate_script $ ./change.sh 04 SEP 2012 10:36:00
root@192.168.12.160's password: 
bash: date -s  : command not found
Connection to 192.168.12.160 closed.
2
  • If that is about setting correct time, why not to use ntp?
    – rush
    Sep 4 '13 at 7:15
  • yeah but i want to try date command along with ssh
    – user46454
    Sep 4 '13 at 7:18
1

There are too many quotes in ssh command.

Use the following one:

 ssh -t -t -o StrictHostKeyChecking=no $USERNAME@${ENVIRONMENT_ARRAY[i]} "date -s '$1 $2 $3 $4'"

also change tsring with change_date function call to:

change_date $1 $2 $3 $4
2
  • i changed in above manner but got diff results its is not changin to the date i am mentioning ./change.sh 04 SEP 2013 10:36:00 root@192.168.12.160's password: Tue Sep 4 00:00:00 IST 2012 Connection to 192.168.12.160 closed.
    – user46454
    Sep 4 '13 at 7:41
  • ah, it looks like your function knows nothing about script parameters. change function call like in updated answer.
    – rush
    Sep 4 '13 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.