I want to write a program which will check if soft links exist or not
#!/bin/bash
file="/var/link1"
if [[ -L "$file" ]]; then
echo "$file symlink is present";
exit 0
else
echo "$file symlink is not present";
exit 1
fi
There will be link2, link3, link4, link5.
Do I have to write the same script n number of times for n number of links or can this be achieved in one script?
Also I want to have the exit 0 and exit 1 so that I can use for monitoring purpose.
fileso that you can reuse it. stackoverflow.com/q/192249/397817forloop to go over the linksfor link in /var/link{1,2,3,4,5}; do [[ -L "$link" ]] || exit; doneis almost certainly more complicated than it needs to be. (exitexits with$?by default, so[[ -L non-existing-file ]] || exitexits with status 1; similarly, the implicit exit at the end of a script likewise uses$?, so the implicit exit from a script whose last command did not fail will always have exit status 0).