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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to run fortune every time I login to FC3. I know you can modify the .bashrc file to run it, but then when I'm in a gui and open a terminal, it displays another fortune, and I don't want that. Any ideas? TIA
You could put it in /etc/rc.d/rc.local, but it would only be displayed on the boot screen, and -- if you are using a graphical boot -- the boot messages are usually hidden.
Ah, here's an idea: have the cookie written to. say, /tmp/cookie, (e.g. fortune > /tmp/cookie) in rc.local. Then put someting in like this in .bashrc
Code:
if [ -f /tmp/cookie ];
cat /tmp/cookie
rm /tmp/cookie
fi
Note: I've not tested any of this, so -- use at your own risk. (There may be a problem since the rc.local script is run by "root," so root will own the cookie file. You may need a "chown" command [in rc.local] before you can remove the cookie file in .bashrc.)
A better idea this morning. This seems to work for me.
Code:
#!/bin/bash
# Make sure we have a local temp directory
# (This is a good thing to have for other uses as well.)
if ! [ -d ~/tmp/ ]; then
mkdir ~/tmp/
fi
# Remove any old cookie file (Assumes .Xauthority is created at each X11 user start)
if [ ~/tmp/cookie -ot ~/.Xauthority ]; then
rm -f ~/tmp/cookie # (The -f is so rm won't complain if ~/tmp/cookie doesn't exist)
fi
# Make and display the new cookie if this is the first run since starting X11
if ! [ -f ~/tmp/cookie ]; then
fortune > ~/tmp/cookie
cat ~/tmp/cookie
fi
---edit
well I thought it did, till I rebooted... won't re-show a new fortune. I noticed a line in your script that says it (Assumes .Xauthority is created at each X11 user start). What does that mean and how can I check it?
Last edited by gpelletier; 04-06-2005 at 03:14 PM.
Hum. What I was doing there was comparing the "Last Modified" time of ~/tmp/cookie with that of a file that I thought would be modified when a new log-on was done. That one looked like a possibility, since it seems to be a "user-level" log file.
Another method might be to set up a shutdown script to delete ~/tmp/cookie. Take a look at /etc/init.d/halt. I think you could add a line in there to delete the "cookie" file. (Or, add a "halt.local" script to /sbin/ to do it.) PROBLEM: I think that tis script may be being run by "root," not the user.
If you just want the cookie after shutdown or reboot, try using /var/lib/randon-seed instead of .Xauthority. According to the "halt" script, that file is updated at each shutdown or reboot. (It's weird that the Linux developers preserve the seed across reboots. That means that any pseudo-random sequence generated by the system will eventually cycle.)
#!/bin/bash
# Make sure we have a local temp directory
# (This is a good thing to have for other uses as well.)
if ! [ -d ~/tmp/ ]; then
mkdir ~/tmp/
fi
# Show the fortune if this is a new login or session
if [ ~/tmp/cookie -ot ~/.qt/qtrc ] || [ ~/tmp/cookie -ot /var/lib/random-seed ]; then
touch ~/tmp/cookie
kdialog --title Fortune --msgbox "`fortune`"
fi
There are several changes:
1) Instead of putting the whole fortune into ~/tmp/cookie, I just "touch" it, which creates an empty file if it doesn't exist, and updates it's time stamp if it does. (This save a fairly minor amount of space, but it is better practice.
2) I display the fortune in a KDE pop-up window. (If you aren't using KDE, just revert to the simple call to "fortune.")
3) The whole "remove" section is deleted, since "touch" is called every time.
Now, all that being said, there is an easier way to do all this if you're using KDE and you just want the fortune displayed when the user starts a KDE session:
1) Create a desktop icon that calls fortune
2) Open the file manager and move the fortune.desktop (Well, I did call mine "fortune.") file from ~/Desktop to ~/.kde/Autostart (Which you may need to create if it's not there.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.