Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to avoid duplicate operation in .cshrc file?

Status
Not open for further replies.

yolande_yj

Full Member level 3
Joined
Jan 20, 2005
Messages
152
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
1,647
I have a file to source in the .cshrc file:

source abc.dat

But this file can be sourced only once. If I log out and log in again, this file should not be sourced again. How can I do that? Thanks.
 

You can create a tempfile in abc.dat:
touch /tmp/.abc.dat_sourced
and detect if this file exists.
 

Hughes said:
You can create a tempfile in abc.dat:
touch /tmp/.abc.dat_sourced
and detect if this file exists.
Can you give me instrution step by steip. Thanks a lot.
 

Code:
if ( ! -e /tmp/.abc.dat_sourced ) then
    touch /tmp/.abc.dat_sourced
    source abc.dat
endif
 

    yolande_yj

    Points: 2
    Helpful Answer Positive Rating
how to delete the .abc.dat_sourced file when Linux is closed? Otherwise that file exit, so I can not source the file again when I restart the OS. And what does -e mean?
 

yolande_yj said:
how to delete the .abc.dat_sourced file when Linux is closed? Otherwise that file exit, so I can not source the file again when I restart the OS. And what does -e mean?
If you system is configured to empty the /tmp directory at startup, you need do nothing to delete .abc.dat_sourced file. Otherwise, you can add a script to the /etc/rcx.d directory to remove the file (x is a number, may be 3).
 

How do I know if the system empty the /tmp folder at startup?
What script should I add?
Thanks
 

yolande_yj said:
How do I know if the system empty the /tmp folder at startup?
What script should I add?
You can find if /tmp is auto-emptied simply by checking if it contains any files before system restarted.

The script is like this:
Code:
#!/bin/sh
if [ -e /tmp/.abc.dat_sourced ]; then
    rm -f /tmp/.abc.dat_sourced >& /dev/null
fi

The exact code and file name depend on your system.
 

    yolande_yj

    Points: 2
    Helpful Answer Positive Rating
My system is Redhat Enterprise AS. Can I use that code? What is the file name? Thanks
 

yolande_yj said:
My system is Redhat Enterprise AS. Can I use that code? What is the file name? Thanks
You may try to name it "KxxRmAbcSourced" (xx is to-digit number) and put it under director "/etc/rc0.d" or "SxxRmAbcSourced" and put it to dir "/etc/rcn.d", where n is 2, 3 or 5 (I am not sure). If you always log in with X environment, you can find the current runlevel by command "who" (may be with "-s" option, you may find it by "man"), and use the current runlevel number as n.
yolande_yj said:
I have a file to source in the .cshrc file:

source abc.dat

But this file can be sourced only once. If I log out and log in again, this file should not be sourced again. How can I do that?
Another solution is use "who" and/or "last" commands to find if the current log-in is the first log-in after reboot.
Code:
#!/bin/sh
mylog=`who -m`
myname=`whoami`
my1stlog=`last | sed -n "/^$myname/ h
/^reboot/ {
x
p
q
}" `
current_login_time=`echo $mylog | cut -d\  -f3-5`
first_login_time=`echo $my1stlog | cut -d\  -f5-7`
[ T"$current_log_time"  = T"$first_login_time ]
Save the above script to "~/bin/IsFirstLogin" (or anything you like), and set it executable by chmod.
Now in your "~/.login" file, add the following lines:
Code:
~/bin/IsFirstLogin
if ($status == 0) then
    source abc.dat
endif

Note that I am not sure if the output of "who" and "last" are consistent with all systems. You can try the following two command:
Code:
who -m | cut -d\ -f3-5
# you must be in the login shell to try the above line
last | cut -d\ f5-7
You the outputs are not as time strings, you can modify the numbers.
Best regards
Hughes.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top