Define Aliases to tail many logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Define Aliases to tail many logs
# 1  
Old 04-07-2010
Define Aliases to tail many logs

Hello Friends,

I defined some Aliases to tail some logs easily as im used to taking logs everyday and many times. I have already given up putting Aliases into .profile and besides a script file as i coudlnt make it work after several attempts. Now i do use them like below and i copy and paste them in every network tool sessions. I have added date part to distinguish logs but it does not work right and after starting logs it records the same date each time. It is enough solution to make date part work each time i start logs, please advise what to do.

Code:
alias spc1="tail -f SPC_CORE_H12_I0.log 
| tee spc1_`date +%d%m%Y_%H%M`.txt";
alias inap1="tail -f INAP_CAMEL_PHASE_2_H12_I0.log 
| tee inap1_`date +%d%m%Y_%H%M`.txt";
alias tcap1="tail -f TCAP_SIGNALING_H12_I0.log  
| tee tcap1_`date +%d%m%Y_%H%M`.txt";

Regards
# 2  
Old 04-07-2010
Hi,
I haven't tested anything yet, but I think the alias is defined by whatever value You get when You issue the alias command, so it will be static. Just type the command alias afterwards and You will see that the date is a constant. I think I would use a script instead.

Best regards,
Lakris

Ha!
"Thinking before You type is like wiping before the dump..."

Try this:
alias my_date="date +%d%m%Y_%H%M;"
alias spc1='tail -f SPC_CORE_H12_I0.log;echo spc1_`my_date`.txt';
...etc

then You will get a dynamic date command.
Smilie

Last edited by Lakris; 04-07-2010 at 06:04 PM.. Reason: Some brain cells came home from a brief stroll around the house...
# 3  
Old 04-07-2010
Quote:
Originally Posted by Lakris
Hi,
I haven't tested anything yet, but I think the alias is defined by whatever value You get when You issue the alias command, so it will be static. Just type the command alias afterwards and You will see that the date is a constant. I think I would use a script instead.

Best regards,
Lakris
hmm yes i had the same thought, so when i type alias command and hit the Enter button it gets the current date and it always uses this current date as a constant when it is run, right?

I have put each Alias command to one line in a script file but it didnt work, how the script file should look like?

When it comes to .profile, my .profile is already so complicated and the Aliases didnt work. I gave up this solution.
# 4  
Old 04-07-2010
You would be better using named scripts rather than aliases.
If you store your scripts in a common directory it is then only necessary to add that directory to $PATH in .profile .

Code:
PATH="${PATH}:/my_common_scripts_directory"; export PATH

# 5  
Old 04-08-2010
Quote:
Originally Posted by methyl
You would be better using named scripts rather than aliases.
If you store your scripts in a common directory it is then only necessary to add that directory to $PATH in .profile .

Code:
PATH="${PATH}:/my_common_scripts_directory"; export PATH

Thanks a lot Methyl, I have written scripts for each tail code rather than defining Aliases and then i put the scripts directory into $PATH in .profile. Finally i can use all the scripts well and i get new logs with right time stamps.
# 6  
Old 05-21-2010
doesn't tail -f require a console...? Not sure if it can be relied upon without an interactive window...

Meanwhile, methyl's suggestion is entirely valid, but before giving up entirely on the multi-pronged effort...you might want to note the syntax errors on the alias suggestions given above and correct these to csh syntax:
Code:
% alias my_date="date +%d%m%Y_%H%M;"

% echo $my_date
my_date: Undefined variable

% set my_date="date +%d%m%Y_%H%M;"

% alias spc1 'echo $my_date '             

% spc1
date +%d%m%Y_%H%M;

% set my_date `date +%d%m%Y_%H%M;`
set: Syntax error

% set my_date=`date +%d%m%Y_%H%M;`

% alias spc1 'echo $my_date '

% spc1
21052010_1439

% touch /tmp/$my_date.log

% ls -lgo /tmp/2*.log
-rw-rw----   1       0 May 21 14:47 /tmp/21052010_1439.log

# 7  
Old 05-22-2010
Quote:
Originally Posted by EAGL€
I have already given up putting Aliases into .profile
You may want to store them in a separate file and make .bashrc source that:

Code:
# ~/.aliases
alias spc1="(definition)"
alias inap1="(definition)"
alias tcap1="(definition)"

Code:
# ~/.bashrc
if [ -f ~/.aliases ]
then
  source ~/.aliases
fi
(original content)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

3. UNIX for Dummies Questions & Answers

Unsetting aliases

Within a session we have created some aliases. How to unset all the aliases in the session or specific alias? (1 Reply)
Discussion started by: pandeesh
1 Replies

4. HP-UX

[Solved] Aliases in HP-UX

Hi folks, How can I make an alias in HP-UX? I've tried to add something just like this bye='exit' (as example), the system accepted but when I write bye in the terminal its return with invalid command. When I make such alias in RedHat or Fedora the system accept it right there, what is the... (7 Replies)
Discussion started by: leo_ultra_leo
7 Replies

5. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

6. Shell Programming and Scripting

etc aliases

Hello: i have several server with own etc aliases. right now i want to combine it all into a general etc aliases in a new freebsd server. cause it consist hundred thousand of record user inside how to make a shell script to combine it or configure it. all etc aliases record example: ... (0 Replies)
Discussion started by: peterLfs
0 Replies

7. UNIX for Dummies Questions & Answers

man aliases

Can any one show me how to create an alias account that silently copies local emails to the administrator (root) using a linux cmd line or GUI? The answer needs to be very simplly explained at this stage, as I am new to the command prompt...expecialy in linux. thanks heaps guys Pipa:) I... (2 Replies)
Discussion started by: Pipa
2 Replies

8. Shell Programming and Scripting

/etc/mail/aliases

HI I have 5000 users on sendmail server, also there entries of these users Mail ID in /etc/mail/aliases as per Diparments. Same Mail ID can occures in Diff Departments as per req. I have to remove 500 users from server also there entry from /etc/mail/aliases file. which occures many times. ... (1 Reply)
Discussion started by: Kumarsharad
1 Replies

9. UNIX for Dummies Questions & Answers

aliases

Is there a way to view what aliases are running on a given session? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

10. Programming

aliases

Hi. I have a C program that is using the **environ pointer and I am trying to set up aliases for a system("/bin/ksh") call. This works for other environment variables but not for the aliases. Does anyone know if this can be done? Thanks ahead of time. (1 Reply)
Discussion started by: mluey61
1 Replies
Login or Register to Ask a Question