Reputation: 1301
I'm trying to make a simple bash script that invokes sftp.
When in interactive mode, whenever the user uses 'put' on a file, I want to echo out some metadata information on that file.
I'm reading the Bash Guide for Beginners on tldp.org, but it's immediately obvious to me on how to write an if statement that checks whenever the user hits the 'put' command.
Thanks.
Edit: Added some basic code and elaboration.
#!/bin/bash
sftp 133.43.453.132 # I made up this IP for demonstration purposes
while True
do
if [user uses 'put' to a transfer a file to remote server] # New to bash so I don't know how to express this.
then
echo "Random stuff"
fi
done
So basically, how do I write this if condition?
Upvotes: 0
Views: 741
Reputation: 19395
A naive approach could be
#!/bin/bash
sftp 133.43.453.132 | tee /dev/tty |
while read prompt command argument1 rest
do
case $command in put) echo "Random stuff";;
esac
done
tee /dev/tty
would be needed.Upvotes: 1