bash - Using rsync in expect script with find -ctime give me an error? -


i need expect script , rsync. when run rsync in command line works fine:

rsync -avz root@10.33.122.22:'$(find /cluster/storage/nobackup/coremw/var/log/saflog/faultmanagementlog/alarm/ -ctime -1)' /home/imstest/shared/generate/reportingt3/tmp/ 

but when use expect script looks error:

#!/usr/bin/expect -f set host_ip [lindex $argv 0 ] set user [lindex $argv 1 ] set password [lindex $argv 2] set scp_remote_directory [lindex $argv 3 ] #set scp_remote_filename [lindex $argv 4]  set local_directory [lindex $argv 4]  set force_conservative 1  ;# set 1 force conservative mode if                           ;# script wasn't run conservatively if {$force_conservative} {         set send_slow {1 .1}         proc send {ignore arg} {                 sleep .1                 exp_send -s -- $arg         } }  set timeout -1 #spawn scp $user@$host_ip:$scp_remote_directory/$scp_remote_filename $local_directory/ spawn rsync -azv $user@$host_ip:\'\$(find $scp_remote_directory -ctime -1)\' $local_directory/ #spawn scp $user@$host_ip:$scp_remote_directory/cscfhealthcheckreport_$tagid_$phase* $local_directory/ match_max 100000 expect {   -exact "are sure want continue connecting (yes/no)? " {     send -- "yes\r"     exp_continue   }   -exact "${user}@${host_ip}'s password: " {     send -- "$password\r"   }   -exact "password: " {     send -- "$password\r"   } } expect eof 

the script name td_general_scp.exp , run this:

./td_general_scp.exp 10.33.122.22 root rootroot /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log /home/imstest/shared/generate/reportingt3/tmp 

but error:

spawn rsync -azv root@10.33.122.22:'$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log -ctime -1)' /home/imstest/shared/generate/reportingt3/tmp/ unexpected local arg: /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log if arg remote file/dir, prefix colon (:). rsync error: syntax or usage error (code 1) @ main.c(1362) [receiver=3.1.0] expect: spawn id exp6 not open     while executing "expect eof"     (file "./td_general_scp.exp" line 36) 

but spawn printout looks same when run in command line? doing wrong?

thanks help!

i addded comments @shubhangi pardeshi error:

spawn rsync -azv root@10.33.122.22:'$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log -ctime -1 )' /home/imstest/shared/generate/reportingt3/tmp/ password:  receiving incremental file list rsync: change_dir "/root//$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm" failed: no such file or directory (2) 

the scripts looks now:

#!/usr/bin/expect -f set host_ip [lindex $argv 0 ] set user [lindex $argv 1 ] set password [lindex $argv 2] set scp_remote_directory [lindex $argv 3 ] set local_directory [lindex $argv 4]  set force_conservative 1  ;# set 1 force conservative mode if                           ;# script wasn't run conservatively if {$force_conservative} {         set send_slow {1 .1}         proc send {ignore arg} {                 sleep .1                 exp_send -s -- $arg         } }  set timeout -1 #spawn scp $user@$host_ip:$scp_remote_directory/$scp_remote_filename $local_directory/ spawn rsync -azv $user@$host_ip:\'\$(find\ $scp_remote_directory\ -ctime\ -1\ )\' $local_directory/ #spawn scp $user@$host_ip:$scp_remote_directory/cscfhealthcheckreport_$tagid_$phase* $local_directory/ match_max 100000 expect {   -exact "are sure want continue connecting (yes/no)? " {     send -- "yes\r"     exp_continue   }   -exact "${user}@${host_ip}'s password: " {     send -- "$password\r"   }   -exact "password: " {     send -- "$password\r"   } } expect eof 

here printout gert when using exp_internal 1 after channging @shubhangi pardeshi suggestion.

spawn rsync -azv root@10.33.122.22:'$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log -ctime -1 )' /home/imstest/shared/generate/reportingt3/tmp/ parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {115454}  expect: "" (spawn_id exp6) match exact string "are sure want continue connecting (yes/no)? "? no "root@10.33.122.22's password: "? no "password: "? no password:  expect: "password: " (spawn_id exp6) match exact string "are sure want continue connecting (yes/no)? "? no "root@10.33.122.22's password: "? no "password: "? yes expect: set expect_out(0,string) "password: " expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "password: " send: sending "rootroot\r" { exp6 }  receiving incremental file list rsync: change_dir "/root//$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm" failed: no such file or directory (2)  sent 8 bytes  received 159 bytes  111.33 bytes/sec total size 0  speedup 0.00 rsync error: files/attrs not transferred (see previous errors) (code 23) @ main.c(1655) [receiver=3.1.0] rsync: [receiver] write error: broken pipe (32) expect: read eof expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "\r\nreceiving incremental file list\r\nrsync: change_dir "/root//$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm" failed: no such file or directory (2)\r\n\r\nsent 8 bytes  received 159 bytes  111.33 bytes/sec\r\ntotal size 0  speedup 0.00\r\nrsync error: files/attrs not transferred (see previous errors) (code 23) @ main.c(1655) [receiver=3.1.0]\r\nrsync: [receiver] write error: broken pipe (32)\r\n" imstest@tca-hubba3:~/shared/generate/reportingt3/bin$  

i missed chang ` suggestion have exact row suggested:

spawn rsync -azv $user@$host_ip:\`\$(find\ $scp_remote_directory\ -ctime\ -1\ )\` $local_directory/ 

but permission denied output? logged in root can't permission problem. error output looks this.

spawn rsync -zv root@10.33.122.22:`$(find /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fm*.log -ctime -1 )` /home/imstest/shared/generate/reportingt3/tmp/ parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {118075}  expect: "" (spawn_id exp6) match exact string "are sure want continue connecting (yes/no)? "? no "root@10.33.122.22's password: "? no "password: "? no password:  expect: "password: " (spawn_id exp6) match exact string "are sure want continue connecting (yes/no)? "? no "root@10.33.122.22's password: "? no "password: "? yes expect: set expect_out(0,string) "password: " expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "password: " send: sending "rootroot\r" { exp6 }  bash: /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fmalarmlog_20160422_152507.log: permission denied  sent 8 bytes  received 5 bytes  8.67 bytes/sec total size 0  speedup 0.00 expect: read eof expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "\r\nbash: /cluster/storage/no-backup/coremw/var/log/saflog/faultmanagementlog/alarm/fmalarmlog_20160422_152507.log: permission denied\r\n\r\nsent 8 bytes  received 5 bytes  8.67 bytes/sec\r\ntotal size 0  speedup 0.00\r\n" imstest@tca-hubba3:~/shared/generate/reportingt3/bin$  

below 2 changes in rsync command in expect script resolve issue

  1. escape space in find command- $(find $scp_remote_directory -ctime -1)
  2. replace ' `

hence, spawn statement in expect script

spawn rsync -azv $user@$host_ip:\`\$(find\ $scp_remote_directory\ -ctime\ -1\ )\` $local_directory/ 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -