One password prompt for bash script including SCP and SSH [SOLVED] -
printing documents printer connected internet slow @ university. therefore i'm writing script sends file remote computer scp, sends series of commands on ssh print document remote computer (which has better connection printer) , delete file on remote computer.
it works charm annoying part prompts password 2 times, 1 time when sends file scp , 1 time when sends commands on ssh. how can solved? read can use identity file? thing though multiple users use , many has limited experience bash programming script must including creating file.
users use mac , remote computer uses red hat. here's code far:
#!/bin/sh filename="$1" printer="$2" # checks if second argument set, else prompt if [ -z ${printer:+x} ]; printf "printer: "; read printer; fi # prompt username printf "cid: " read cid scp $filename $cid@adress:$filename ssh -t $cid@adress bash -c "' lpr -p $printer $filename rm $filename exit '"
you don't need copy file @ all; can send lpr
via standard input.
ssh -t $cid@adress lpr -p "$printer" < "$filename"
(ssh
reads $filename
, forwards remote command.)
Comments
Post a Comment