Autostart script in ubuntu

1. Problem

I want to run some scripts when the machine is powered up.

2. Analysis

Ubuntu save autostart scripts in /etc/xdg/autostart/. All the files in this folder will run automatically. So I just need to create my custom file in this folder. You can use gnome-session-properties to call a window applicantion.

3. Solution

3.1 Prepare scripts

3.1.1 rjsupplicant.sh
sudo vim /etc/init.d/rjsupplicant.sh
#!/bin/bash
echo [sudo password] | sudo  -S /opt/rjsupplicant/rjsupplicant.sh -d 1 -u [username] -p [rj password] -S 1 &
sudo chmod +x /etc/init.d/rjsupplicant.sh
3.1.2 inform_ipaddr.sh
sudo vim /etc/init.d/inform_ipaddr.sh
#!/bin/bash
echo `ifconfig | grep -i "inet addr"` | mail -s dl_machine_ipaddr mailaddr@qq.com
sudo chmod +x /etc/init.d/inform_ipaddr.sh

Be sure you have installed sendmail tool. More details here.

3.2 Add scripts to autostart

sudo vim /etc/xdg/autostart/rjsupplicant.desktop
[Desktop Entry]
Type=Application
Name=rjsupplicant
Comment=Log in RuiJie
Exec=/etc/init.d/rjsupplicant.sh
NoDisplay=false
sudo vim /etc/xdg/autostart/inform_ipaddr.desktop
[Desktop Entry]
Type=Application
Name=inform_ipaddr
Comment=Tell about IP address using e-mail
Exec=/etc/init.d/inform_ipaddr.sh
NoDisplay=false

3.3 Test

sudo reboot

Done.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值