Operating System - HP-UX
1752648 Members
5780 Online
108788 Solutions
New Discussion

call script file in .profile

 
SOLVED
Go to solution
Amir Haboosheh
Frequent Advisor

call script file in .profile

I have this script in each users's profile that I don't want to login with more than one session.

after the script i run a program with another exit command at the end. the problem is when i try to call a file that has this script, the exit command doesn't logout the user it just echo's the "...already logged in" text and then runs the other program.

 

# Check if the user is logged in #
telsession=$(who | grep $LOGNAME | wc -l)
if [ ${telsession} -ge 2 ]
then
clear
echo "You are already logged in"
exit
fi

5 REPLIES 5
Dennis Handly
Acclaimed Contributor
Solution

Re: call script file in .profile

Instead of executing the script, why not "source" it?  That way it is running under control of the original .profile.

Amir Haboosheh
Frequent Advisor

Re: call script file in .profile

how do you source it?

James R. Ferguson
Acclaimed Contributor

Re: call script file in .profile


@Amir Haboosheh wrote:

how do you source it?


"Sourcing" is done in the Korn, POSIX (which is the so-called HP-UX shell), and the bash shell with a dot-charater, followed by whitespace, followed by the name of the file to be sourced:

 

. file_to_source

The Bash shell can also use the keyword 'source' in leu of the dot.

 

Regards!

 

...JRF...

Amir Haboosheh
Frequent Advisor

Re: call script file in .profile

thank you both. the source command didn't work but the "." did

 

thanks again.

Dennis Handly
Acclaimed Contributor

Re: call script file in .profile

>the source command didn't work but the "." did

 

Of course, you are using a real shell, not bash nor the scummy C shell.