Hey I'm working on this all purpose script to tighten a ubuntu computers security and one of the things in it is to disable guest account through lightdm.conf. The way my script is setup or at least I want it to be setup is that if it doesn't find lightdm.conf it will make the file and insert the text. Any help would be appreciated.
#!/bin/bash
read -p "Disable guest account? yes or no: " ans
case "$ans" in
yes) if locate /etc/lightdm/ |grep lightdm.conf
then
sed -i '$ a [SeatDefaults]' /etc/lightdm/lightdm.conf &&
sed -i '$ a user-session=ubuntu' /etc/lightdm/lightdm.conf &&
sed -i '$ a greeter-session=unity-greeter' &&
sed -i '$ a allow-guest=false' /etc/lightdm/lightdm.conf &&
echo "Guest account disabled succesfuly"
else cat > /etc/lightdm/lightdm.conf
sed -i '$ a [SeatDefaults]' /etc/lightdm/lightdm.conf &&
sed -i '$ a user-session=ubuntu' /etc/lightdm/lightdm.conf &&
sed -i '$ a greeter-session=unity-greeter' &&
sed -i '$ a allow-guest=false' /etc/lightdm/lightdm.conf && echo "Guest account disabled"
fi
;;
no) echo "Will not disable guest account "
esac
sed
is a scripting language. Invoking it four times to execute four commands is incredibly inelegant and inefficient, especially if you rewrite the output file at each stage. You separate commands with newlines or semicolons, or pass in multiple-e
options. For example,sed -i -e 's/foo/bar/' -e '234q' filename
– tripleee Nov 30 '15 at 06:14