Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some parameters that I would like to change in /etc/xdg/lxsession/LXDE/autostart, before it is run. I get the parameters from a grep command. I would like to feed them to the autostart file but am not sure how.

Currently, what I have is grep "stuff" /file/one which outputs 1234.

I want to put 1234 in the autostart file like

....
@program 1234
....
share|improve this question
add comment

1 Answer

As always, there is probably a million ways to do this and the way I read your question your are going about your problem the wrong way, but first things first.

After entering your username and password correctly all the scripts in /etc/X11/Xsession.d are sourced (not run, that's a very important difference!) in alphabetical order. So if you want some logic to happen after login, but before your desktop environment starts, that's the place to put your scripts.

In such a script you could put

for item in $(grep "stuff" /file/one)
do
  echo "@program ${item}" >> /etc/xdg/lxsession/LXDE/autostart
done

That will add the lines you want to file you want to add them to. It's the '>>' that makes the shell append the lines to the end of the file, rather than replacing the file. That's the answer to your question.

Now here's the problem: with such a script the result of your grep will be added to the autostart file every time you log in to your machine. So the first time that program will be run once. The next time you log in twice and three times on your next login. The list of your autostart programs will keep growing as long as your grep yields results to add to the autostart file. That's why I initially said you are going about your problem the wrong way.

Further, there is not just the global /etc/xdg/lxsession/LXDE/autostart. You can have a file ~/.config/lxsession/LXDE/autostart for each individual user. Even if you are the only user working on your machine you should rather edit the file in your home directory (~ expands to your home directory) than the global one.

And as final advice if you want to run programs, just add an entry to your ~/.config/lxsession/LXDE/autostart for a shell script that does a for loop as stated above, but instead of adding lines to some file you actually run the commands. When you run commands with an & at the end of the line those programs will be run in the background and the script will not block.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.