LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-05-2005, 11:08 PM   #1
gpelletier
LQ Newbie
 
Registered: Apr 2005
Distribution: FC3
Posts: 3

Rep: Reputation: 0
question with using a login script


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

 
Old 04-06-2005, 12:00 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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.)
 
Old 04-06-2005, 10:51 AM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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
Hey, "fortune's a fun program!
 
Old 04-06-2005, 03:51 PM   #4
gpelletier
LQ Newbie
 
Registered: Apr 2005
Distribution: FC3
Posts: 3

Original Poster
Rep: Reputation: 0
that worked as I wanted it to. Thank's

---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 04:14 PM.
 
Old 04-07-2005, 04:59 PM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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.)
 
Old 04-07-2005, 08:48 PM   #6
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
OK, here's another shot at it.
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

# 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.)

Done.

Hey, this is fun. (But my wife hates you.)
 
Old 04-09-2005, 10:08 PM   #7
gpelletier
LQ Newbie
 
Registered: Apr 2005
Distribution: FC3
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by PTrenholme

Hey, this is fun. (But my wife hates you.)
sorry bout that... that is the problem with fortune... it's a little addicting

---edit
actually I thought of a way to make it so fortune only displays on initial logon. I just put it into my .bash_profile

Last edited by gpelletier; 04-09-2005 at 10:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 11:09 AM
Login script unclejessie77 Programming 5 02-24-2005 01:30 PM
login-script thermite_1033 Linux - Security 2 09-28-2004 05:54 PM
login script notREALly Linux - General 6 11-29-2003 09:23 AM
login script oneringsol Linux - Newbie 2 11-03-2002 09:45 PM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration