osx - Bash script: How to remote to a computer run a command and have output pipe to another computer? -
i need create bash script able ssh computer or machine b, run command , have output piped .txt file on machine how go doing this? list of computers ssh , run command of output append same .txt file on machine a.
update: ok went , followed other guy suggested , seems work:
file=/library/logs/file.txt ssh -n username@<ip> "$(< testscript.sh)" > $file
what need instead of manually entering ip address, need have read list of hostnames coming .txt file , have place in variable substitute ip address. example be: ssh username@variable in "variable" changing each time word read file containing hostnames. ideas how go this?
this should it
ssh userb@machineb "some command" | ssh usera@machinea "cat - >> file.txt"
with commands:
ssh userb@machineb <<'end' | ssh usera@machinea "cat - >> file.txt" echo hostname=$(hostname) lastchecked=$(date) ls -l /applications/utilities/disk\ utility.app/contents/plugins/*partition.dumodule* | awk '{printf "username=%s datemodified=%s %s %s\n", $3, $6, $7, $8}' end
you replace ls -l | awk
pipeline single stat
call, appears osx stat not have way return user name, user id
Comments
Post a Comment