Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm trying to get a script to autostart and hitting some snags.
I know the script works, because I can manually launch it from a terminal window.
I've perused the forums and followed similar advice to put the script in the /etc/rc.d/init.d directory and then create a symlink in the rc5.d directory (S99my_script)
I've even tried appending ". /etc/init.d/myscript" to the .bashrc file
I've managed to get the machine to autologin "myuser" upon startup (that's the owner of the .bashrc file I edited), but still the script won't start when myuser auto logs in.
the system default is set for password protect on screen save so if I simple let that happen, as soon as I exit screen save the script launches, so it almost works ...
First determine if the script is even being invoked at all.
Tip top line of the script should be a comment that indicates the shell, and the shell does look at this to determine which shell it's supposed to use. Example:
I always also place in the following lines, and comment in or out depending on whether I need to debug:
When uncommented, you'll see in the window from which you run, the flow of your script. But when running via the /etc/init.d method you'll not see this output, so this is not relevant, but simply a suggestion for debugging your scripts for when you run them manually.
Next piece of general purpose advice is for every shell command you invoke from within your script, make sure you understand whether or not it is a symbolic link, and what the path for it is:
For instance, if you run "tar" from within your script; outside of your script in a shell window, type "which tar" and determine the path tar is run from, likely /bin/tar and from within your script, always invoke tar as /bin/tar, and not just "tar" because you should not make assumptions about your environment from within the script.
Next advice is to echo information to a log file. /bin/echo "got to this line" >> /home/myuser/script.log
You can also debug the environment from within your script: env >> /home/myuser/script-environ.log
Check the outcome of commands you wonder about:
/bin/tar -tvf myfile.tar
echo "Outcome of the tar operation was $?" >> /home/myuser/script.log
If that number is anything but ZERO, then tar failed for some reason.
Further, I'm not too great at it, I usually have to work at it, but you can output stderr to the log file also:
the OS involved is CentOS 5.3
I changed the first line in the script from #!bin/bash to #!bin/sh - now when the machine boots, it runs the script momentarily, but then drops through to the desktop (the script launches an image viewer that plays a looped slideshow)
As soon as I open a terminal window, the script runs again.
so now: why the detour to the desktop?
It really depends on what you've written your script to do; when you launch it; whether or not it depends on the Xserver to be there. For instance, if you wrote some script that does a slideshow as you say, then it needs the Xserver to be there. I'd recommend that you run the script from your own personal .bashrc in your home directory versus out of the /etc/init.d tree. S##name = "Start" numbers starting from 01 - 99 in order the linked script. I doubt you want to be before udev, or the Xserver in this case. Hence, if udev is like S03 and Xserver is S20 in the rc5.d directory, then you'd not want to start your script until say S99 just to make sure the rest of the system is up and running first.
But from what I've seen, you auto-login, hence no password, or remembered password and load up your own user's desktop. Is the shell BASH? To check that issue "env | grep SHELL" and you should see something like "SHELL=/bin/bash". That means the BASH shell, and that means in your home directory, /home/<yourusername> you can have a file (likely already do) called .bashrc; which sets up the "your user" specific aliases, paths, and can run scripts for you.
I would run this script out of your own .bashrc and have it be the last thing you do in that file.
From what it sounds like, you can run this script from an Xterminal from within your own login, correct? Then it should work from within your .bashrc.
I boot up the PC (Compaq Armada laptop) and it auto logs in myuser.
the slide show starts, but as soon as the desktop fires up, the slide show is interrupted.
if I open a terminal window, the script resumes.
there's a symlink in /etc/rc.d/rc5.d called S99slideshow that points to /etc/rc.d/init.d/slideshow
here's the rest:
[dpf@localhost ~]$ cat .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
# User specific aliases and functions
[dpf@localhost ~]$ cat /etc/rc.d/init.d/slideshow
xset s off &
xset s noblank &
xset -dpms &
feh -f /home/dpf/pix/*.* -F -Z -D 5 &
I commented out the ./slideshow line in the .bashrc file and the script failed to launch upon reboot (I test this by opening a terminal window and issue an xset -q to check the status of the screen saver - it should be disabled if the script runs)
I removed the symlink (S99slideshow) and the script from the /etc/rc.d/init.d directory and re-activated (un-commented) the line in the .bashrc file and the script launches upon reboot and runs up until such time as the desktop displays; then it "hibernates" until I do something, like opening a terminal window, at which time the script resumes.
why is the desktop stepping on the script? do I need to include some sort of DISPLAY command?
thank you, John.
I think, perhaps I'll get current and recommence my project.
(BTW - I've managed to make this work using Suse and now am attempting some 'enhancements' to the project that I couldn't get to work in that OS)
ok - upgraded to CentOS version 5.6 pursuant to John's post.
the script starts on boot up but is still getting "stepped on" when the desktop starts.
if I open a terminal window, the script launches (or resumes)
opening any other application simply opens that app, not the script.