Shell Scripting PAM Login Notification Centos Edit the file : /etc/pam.d/sshd vi /etc/pam.d/sshd Add this line to the above file : session optional pam_exec.so /path/to/script.sh Now Create the Script that will send the notification : vi /path/to/script Paste The Following content, and adjust the admin email
Shell Scripting Reference first argument in move command mv /path/to/dir/filename.txt !#^:h/newname.txt Where : ! means history expansion # means command currently being typed ^ means the first argument :h gets the “head” that is the directory without the filename portion
Shell Scripting Reading an Input From File Reading an input from a file: Command #tr ‘a-z’ ‘A-Znewfilename
Shell Scripting Time Saving CLI Techniques $ echo {x,y,z} x y z $ echo a{x,y,z} ax ay az $ echo {{1,2,3},1,2,3} 1 2 3 1 2 3 $ echo {{1,2,3}1,2,3} 11 21 31 2 3 $ cp /etc/samba/smb.conf{,.bak} >CTRL + R to search
Shell Scripting Simple yes no input shell script Simple shell script to get user confirmation echo “Do You wish to Continue ?: ” read response if [ $response = “y” ];then echo “You entered yes” echo “Please Wait..Window Will Close When Done” sleep 10 ……………… echo “Done…Exiting Now” sleep 2 …………………. exit fi
Shell Scripting Disable Traps ctrl c , ctrl z in shell script Use the following line in the beginning of your shell script to disable traps like ctrl c and ctrl z in your shell script. trap “” 2 20