Skip to content

Instantly share code, notes, and snippets.

@the-moog
Created November 7, 2024 04:49
Show Gist options
  • Save the-moog/06fe4f5bde0c182ac9be31a5e267267d to your computer and use it in GitHub Desktop.
Save the-moog/06fe4f5bde0c182ac9be31a5e267267d to your computer and use it in GitHub Desktop.
Running remote sftp commands from a script
# use the source, Luke
# > source remote-sftp.shsrc
action="df -h\nexit\n"
for d in / /vol /vol/homes /vol/Public; do
echo "${d}:"
echo -e "${action}" | sftp "user@fs1:${d}"
echo "${d}/:"
echo -e "${action}" | sftp "user@fs1:${d}/"
echo -e - '----\n'; done > result.log
# Return to avoid executing the example output, below
return
##################
> source remote-sftp.shsrc
> cat result.log
/:
Changing to: /
sftp> df -h
Size Used Avail (root) %Capacity
400MB 338MB 62.0MB 62.0MB 84%
sftp> exit
//:
Changing to: //
sftp> df -h
Size Used Avail (root) %Capacity
400MB 338MB 62.0MB 62.0MB 84%
sftp> exit
- ----
/vol:
Changing to: /vol
sftp> df -h
Size Used Avail (root) %Capacity
16.0MB 0BB 16.0MB 16.0MB 0%
sftp> exit
/vol/:
Changing to: /vol/
sftp> df -h
Size Used Avail (root) %Capacity
16.0MB 0BB 16.0MB 16.0MB 0%
sftp> exit
- ----
/vol/homes:
Changing to: /vol/homes
sftp> df -h
Size Used Avail (root) %Capacity
1.5TB 743GB 779GB 780GB 48%
sftp> exit
/vol/homes/:
Changing to: /vol/homes/
sftp> df -h
Size Used Avail (root) %Capacity
1.5TB 743GB 779GB 780GB 48%
sftp> exit
- ----
/vol/Public:
Changing to: /vol/Public
sftp> df -h
Size Used Avail (root) %Capacity
1.5TB 743GB 779GB 780GB 48%
sftp> exit
/vol/Public/:
Changing to: /vol/Public/
sftp> df -h
Size Used Avail (root) %Capacity
1.5TB 743GB 779GB 780GB 48%
sftp> exit
- ----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment