Last login: Sat Feb 11 15:08:20 2023 from 192.168.1. /home/nixcraft/scripts The following line sets the shell variable i to /home/nixcraft/scripts: i dirname / home / nixcraft / scripts / foo.sh echo 'i' OR i (dirname / home / nixcraft / scripts / foo.sh) echo 'i' In bash script use 0 instead of /home/nixcraft/scripts/foo. NOTE: /etc/bashrc has warnings about modifying it which likely should be heeded, instead relying on its recommendations to put customizations in another file that it calls automatically.Īnd this outputs on my little laptop/fedora server sitting next to me in my home office, demonstrating similar command execution from its. I checked and that, too, worked as expected. bashrc templates have this in them: #Source global definitions That said, I'm guessing that if you want your reminder to work for everyone, then you would simply put it in /etc/bashrc, as all my. OP did not indicated what OS the script runs on. And they're easy to check - log out and back in!! bashrc file that loads every time I log in. I have a number of commands at the end of my. Not sure how/why, but in 2023 all of these workarounds are superfluous on AWS EC2 running Amazon Linux, and I suspect on other Linux as well. I see this was last asked 10 years ago, but us noobs keep coming along. As mentioned, it really isn't the way to do it, but works for now. This soulution assumes having automatic log-on set up. Su - YOURUSERNAME -c '/usr/local/bin/script_file.sh -optional -flags' # Run the script as YOURUSERNAME instead of root: If no filename is given as argument, script will automatically create a file namely typescript in the home directory to save the recorded information. Until ] & ] doĮcho "Xserver hasn't started or other error occurred. Syntax: script options file Example 1: To start a typescript without any argument. # Wait until X is running and required user logged in: # Description: runs '/usr/local/bin/script_file.sh -optional -flags' at startup, when xserver has started and YOURUSERNAME is logged on. # Provides: script_file.sh startup at boot Since my script requires xserver and user to be logged on, I created initfile which waits after bootup for xserver and user to be logged on and then executes the script: #! /bin/bash Don't know why it doesn't work for me perhaps it has something to do with my display manager auto logon workaround, just a guess.Īnother solution would be adding script shortcuts to global file that gets executed at startup, for instance /etc/rc.local. It's dirty one though.įirst of all, using ~/.bash_profile, ~/.bash_login, ~/.profile or even /etc/profile.d/ should be preferred methods instead (here's good reading on the subject). Okay, I've found a solution to my initial problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |