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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -