Tuesday, December 27, 2016

16.04 - How to startup a script automatically after login



I Have a Ubuntu Headless Server and I want to run a basic script after I login how can I configure my server to run the script automatically after login?
Script:




clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0


You can add those lines at the end of your ~/.bashrc file which will get executed when you login.




I'm talking about the ~/.bashrc serverside. When you have added your lines and logout and ssh back in these lines will get executed. You can leave out the last line of your script.



If the ~/.bashrc does not exist you can simply create it or even better copy it:



cp /etc/skel/.bashrc ~/.bashrc


and make sure your ~/.profile file contains the following lines:




# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...