I have these two commands that I need to manually run every time after login:
autossh -M 2000 -N -f -q -D 127.0.0.1:7070 and
sudo mkdir /media/C
sudo mount /dev/sda2 /media/CI'd like to make them automatically run every time I boot and login to my computer. I'm currently using 10.04LTS.
BTW, I only vaguely know what init.d or runlevel mean. But I still prefer to know a command-line based way to achieve this, not a fancy GUI way. Also, the autossh will only succeed after Ubuntu automatically detect and connect to my network, so should we let it retry infinitely until successfully executed?
Thank you!
32 Answers
Adding the autossh Command
- On the panel select
System-->Preferences-->Startup Applications. - Under the
Startup Programstab select theAddbutton. - Choose any Name you want and paste in your command (the Comment is optional)
- Click the
Addbutton.
Note for newer versions of Ubuntu
You can find this application by searching for "Startup Applications" in the dash. Also,
you can always launch it by pressing Alt + F2 (or opening a terminal) and running gnome-session-properties.
Mounting the Partition
Option 1: Add partition to /etc/fstab
- See How to mount NTFS drive at startup if it is a Windows partition.
- Ubuntu Community Fstab documentation
Option 2: Use udisks
Add this startup command as shown previously:
udisks --mount /dev/sda2 5 - Create a script file, e.g. named
my_file.sh, in the/etc/profile.d/directory. - Put
#!/bin/bashas the first line. - Write whatever command(s) you want to be executed immediately after logging in, e.g.
pgrep udhcpd. - Mark your file as executable:
chmod +x /etc/profile.d/my_file.sh
*It should get executed after login. In case it doesn't or you don't have the ability to use root privileges, creating the same file under ~/.config/autostart should work fine (I haven't tried this directory before).