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.

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

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.
:slight_smile:

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.

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 .

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.

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:

% 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

You may want to store them in a separate file and make .bashrc source that:

# ~/.aliases
alias spc1="(definition)"
alias inap1="(definition)"
alias tcap1="(definition)"
# ~/.bashrc
if [ -f ~/.aliases ]
then
  source ~/.aliases
fi
(original content)