Tips and tricks

script to remove pictures via ssh

#!/bin/bash
#
#
#
# Johan Kindstrand

#Variabler
servers=(x.x.x.x)
file_path=”[Destination to directory]”

clear
echo “Starting script to delete pictures from servers”
sleep 1

echo “Paste name of picture, followed by [ENTER]:”
read filename

read -r -p “Are you sure? [y/N] ” response
response=${response,,}
if [[ $response =~ ^(yes|y)$ ]]
then
for server in “${servers[@]}”
do
test=$file_path/$filename
#connecting to server and removing cached picture
ssh [user]@$server “if [ -f $test ]; then “rm -r $test”; else echo $test file does not exists; fi”

sleep 1

done
else
echo “bye”
exit

fi