Run shell script after login

Hi,

I'm very new to FreeBSD so have mercy. I want to run a shell script after an autologin of root. I've searched the web but i didn't find a solution. I've managed to make the user root to autologin but now I'm stuck at running the shell script after that autologin.

Can somebody explain me what I have to do?
 
Try put script in .login if you are using [cmd=]csh or tcsh[/cmd] SHELL.
For [cmd=]bash[/cmd] SHELL use .bash_profile
 
i tested, I added some fortunes to .login like
[ -x /usr/games/fortune ] && /usr/games/fortune freebsd-tips
even i created script, i named it con
Code:
#!/usr/local/bin/bash
WGET="/usr/local/bin/wget"
$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
        echo "no"
else
        echo "yes"
fi
and i putted it it .login like:
/usr/local/bin/bash con
 
grigorovl said:
Is there any particular reason for this statement? I can't imagine shell scripting if it's not bash.

Well, you have to expand your imagination then. :)

Portability for example. Not every OS (and not even FreeBSD) has bash in its base system. Why would you mess up your script and make it not portable to other systems? What is in your script that you have to use bash-ism?

I totally agree with @wblock on this one. I always swear when I see someone writing plain shell scripts using bash, particularly in the install scripts.
 
One argument is that it's still very hard to get bourne shell scripts right, you're dealing with text output from filters with all kinds of different quotation rules and the "programming language" is seriously handicapped when compared to lets say perl or python. Why bother with a bourne shell script when a perl program is much easier to write and get it to do exactly what you want?

On the other hand the times when you have to write the script in bourne shell you really want to keep it minimal and not rely on fancy extensions that only exist in lets say bash.
 
Beyond the compatibility issues, bash not being part of the base FreeBSD system means that scripts with
Code:
#!/usr/local/bin/bash
will fail when the system boots in single-user mode and /usr/ isn't mounted.
 
That so-called huge difference between bash and sh scripts is very exaggerated. Most bash scripts can be run as sh scripts, simply by changing
Code:
#!/usr/local/bin/bash
to
Code:
#!/bin/sh
. The only thing I had to change when I changed some old bash scripts was replacing "==" with "=" in some statements. It's not much work at all.
 
junkman said:
I want to run a shell script after an autologin of root.
Man, this almost gave me a heartattack. Autologin of root? What on earth for?

You're not using windows anymore so stop doing everything as root/administrator. Learn to use su(1) and/or sudo(8).

Seriously. This is an accident waiting to happen.
 
junkman said:
Hi,

I want to run a shell script after an autologin of root

I hope autologin is a mistake. I will not do autologin even for my grandma!
By the way, why as root? If your problem is a privilige one, than consider using cron, periodic, rc scripts or something alike.
If what you want to do is to spy root (as on a shared machine), than you should consider using sudo and disabling root at all.
 
Virtualization is not a way to obtain a more secure or a simply secure system.
The scenario you presented is, in my opinion, a bad one. It does not matter you run it with a machine disconnected from the net at all or on a web server.
 
Calm down boys. I use FreeBSD in VirtualBox.

I do understand -- I too have some VMs in VMware with no root password set .. and I sleep ok ;) [ they are only my personal sandbox though ]

But maybe /etc/rc.local is what you're looking for .. better than some hidden profile woodoo execution. Also note that $profile can be sourced anytime somebody su-es to root, etc.
 
matoatlantis said:
I do understand -- I too have some VMs in VMware with no root password set .. and I sleep ok ;) [ they are only my personal sandbox though ]

But maybe /etc/rc.local is what you're looking for .. better than some hidden profile woodoo execution. Also note that $profile can be sourced anytime somebody su-es to root, etc.

That's my case too, personal "learning sandbox". /etc/rc.locale is not present in my FreeBSD machine.
 
I'm using: #! /bin/sh
however, i'm still working on the syntax of how to insert it into the .login
I want personalized login greetings for each User
My dream is a greeting, the calendar with any schedule events, the last few files opened by the User, and
OH BOY if I could get the weather stats from Wunderground.com for location of terminal! I be doing backflips for WEEKS :)
 
If you are looking for something to run at boot time, you could either create an rc.d script or use crond to execute with an @reboot command in the crontab(5).
 
Back
Top