WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Auto-start programs via custom boot code from ~/.X.d  (Read 2046 times)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Auto-start programs via custom boot code from ~/.X.d
« on: March 16, 2016, 09:21:31 AM »
I have this script in  ~/.X.d
Code: [Select]
BOOTCODES="$(cat /proc/cmdline)"
XEXEC="$(echo $BOOTCODES | grep -o 'xexec=".*"')"
if [ -n "$XEXEC" ] ; then
XEXEC="$(echo $XEXEC | sed 's:.*xexec="\(.*\)".*:\1:')"
else
XEXEC="$(echo $BOOTCODES | grep -o 'xexec=.*' | cut -d '=' -f2 | awk '{print $1}')"
fi
[ -n "$XEXEC" ] && sh -c "$XEXEC" &


It checks the boot codes for  xexec=  and, if found, executes whatever value it contains.

This can be useful if something should be executed on almost every boot, but with the possibility of excluding it from boot code if desired.
Of course, it's also possible to add anything to run it just for the current boot.

In my case, I start Firefox and a script that starts my 3G modem connection, so I have this in my boot loader's config:
Code: [Select]
xexec="firefox & /opt/net_connect.sh"
The thing is, if the 30-days I have payed for are over, I can still go online, but I would pay for the amount of downloaded data which is ridiculously expensive.

--

I think there are other solutions to this posted on the forum, but I couldn't find them right away so I came up with this.

As always, recommendations welcome.
Download a copy and keep it handy: Core book ;)