All alias in .profile lost when "script" command is called


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users All alias in .profile lost when "script" command is called
# 1  
Old 12-02-2008
All alias in .profile lost when "script" command is called

Hi,
I was trying to call "script <an ip add>" command from .profile file to log everything whenever anyone logs in to this user. I did the following at the end of .profile. 1) Extracted the IP address who logged in 2) Called script < ip add> . The problem I am facing is all, aliases etc. written in .profile gets lost after "script command is executed. Plz suggest some way so my aliases are preserved after script command executes. Note: I dont have the access to /etc/profile, as i am not the root user.
# 2  
Old 12-02-2008
I don't see what you did that clobbered .profile. Or do you mean that the aliases inside the .profile are not visible within the script session? That's because aliases are not inherited from the environment -- they are read on entry to an interactive shell. script sessions aren't considered interactive because (I think) the output is sent to another program (ie, script). In order to make your aliases usable, you should put them in .bashrc or .kshrc (depending on your shell).


Oh, in case you are trying to implement some security system for hackers so you can monitor their activity, search for "honeypot", the name given to such mechanisms. You might find something out there that you can cater to your needs.
# 3  
Old 12-02-2008
Hi,

I would say the standard way was to remove all Bash alias and function definitions from your ~/.bash_profile or ~/.profile and instead put them in the file ~/.bahsrc (create that file if it doesn't yet exist).
Then to your account's ~/.profile or ~/.bash_profile add these lines:
Code:
BASH_ENV=$HOME/.bashrc
if [ -f $BASH_ENV ]; then
    . $BASH_ENV
    export BASH_ENV
else
    unset BASH_ENV
fi

Now you should have your alias defs available for each shell you spawn anew.
Refer to man bash for details.
# 4  
Old 12-03-2008
Thanks.. works welll...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Any way to "alias" file patterns for use in a command?

First, I apologize for my 'noobness' with Linux and the shell. I'm running Ubuntu with zsh as my shell. What I'd like to be able to do is clean up a messy Downloads folder by moving categories of files to different directories with something like: mv dir/$vids dest mv dir/$music dest mv... (5 Replies)
Discussion started by: Apollo33
5 Replies

4. UNIX for Dummies Questions & Answers

Problems with "exit" called from function in bourne script

Hi everyone. #!/sbin/sh EXITING() { umount /FOLDER rm -Rf /FOLDER echo "EXIT" exit 0 } EXITING echo "OK" (8 Replies)
Discussion started by: vacadepollo
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

the meaning of "!:*" in "alias foo 'command\!:*' filename"

Hi: How can I remove my own post? Thanks. (2 Replies)
Discussion started by: phil518
2 Replies

7. UNIX for Dummies Questions & Answers

Expect "interact" fails when called from another script

So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly. Now I'd like to apply this script... (2 Replies)
Discussion started by: treesloth
2 Replies

8. Shell Programming and Scripting

Idea for an "informative" bash alias or script

I had the idea come into my head that it would be good to have a single command that gave file type, file size, last modification date, and owner/group information, like what one would see in a GUI "Properties" dialog, but all in a terminal window. In my opinion, these statistics about a file... (5 Replies)
Discussion started by: SilversleevesX
5 Replies

9. UNIX for Dummies Questions & Answers

Alias, function or script (bash) to "revert" cd command?

In all of my brief and superficial experience with Unix or Linux, the one curious and consistent thing has been that 'cd ./' (back up one directory level) has done absolutely nothing in any of them. Now I understand that, at least for bash, 'cd ./' appears to have been substituted by 'cd ..' Am... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

10. UNIX for Dummies Questions & Answers

Where can I read about the difference between "..profile" and ".profile"

Hi I know from reading O Riley's Classic Shell Scripting' that the .profile file is " the shells configuration file" but I am unable to find a reference to what "..profile" means. I have searched on the net, Sams Teach Yourself Unix, Unix Visual Quickstart Guide and Linux in a Nutshell. I have... (2 Replies)
Discussion started by: zorrokan
2 Replies
Login or Register to Ask a Question