0
background
I always tail logs (both error and info).. which requires the following manual steps 1. ssh into a server 2. cd into the logs directory 3. identify the last file that is either error or info 4. tail into it
this is what a typical log directory looks like:
error-2017-12-11.log error-2017-12-30.log error-2018-01-05.log error-2018-01-11.log error-2018-01-17.log error-2018-01-23.log error-2018-01-29.log info-2017-12-26.log info-2018-01-01.log info-2018-01-07.log info-2018-01-13.log info-2018-01-19.log info-2018-01-25.log info-2018-01-31.log
error-2017-12-13.log error-2017-12-31.log error-2018-01-06.log error-2018-01-12.log error-2018-01-18.log error-2018-01-24.log error-2018-01-30.log info-2017-12-27.log info-2018-01-02.log info-2018-01-08.log info-2018-01-14.log info-2018-01-20.log info-2018-01-26.log info-2018-02-01.log
error-2017-12-26.log error-2018-01-01.log error-2018-01-07.log error-2018-01-13.log error-2018-01-19.log error-2018-01-25.log error-2018-01-31.log info-2017-12-28.log info-2018-01-03.log info-2018-01-09.log info-2018-01-15.log info-2018-01-21.log info-2018-01-27.log info-2018-02-02.log
error-2017-12-27.log error-2018-01-02.log error-2018-01-08.log error-2018-01-14.log error-2018-01-20.log error-2018-01-26.log error-2018-02-01.log info-2017-12-29.log info-2018-01-04.log info-2018-01-10.log info-2018-01-16.log info-2018-01-22.log info-2018-01-28.log info-2018-02-03.log
error-2017-12-28.log error-2018-01-03.log error-2018-01-09.log error-2018-01-15.log error-2018-01-21.log error-2018-01-27.log error-2018-02-02.log info-2017-12-30.log info-2018-01-05.log info-2018-01-11.log info-2018-01-17.log info-2018-01-23.log info-2018-01-29.log outfile
error-2017-12-29.log error-2018-01-04.log error-2018-01-10.log error-2018-01-16.log error-2018-01-22.log error-2018-01-28.log error-2018-02-03.log info-2017-12-31.log info-2018-01-06.log info-2018-01-12.log info-2018-01-18.log info-2018-01-24.log info-2018-01-30.log
I want to create a command alias that lets me do this from a remote machine instantly
question
doing this as a single command on the remote server is easy (grep info
for info, and error
for error):
tail -f `ls -Art | grep info | tail -n 1`
but when I try to run this alias:
alias logger='ssh -i /file.pub user@host -t
"cd /path/to/logs; tail -f `ls -Art | grep info | tail -n 1`; bash --login"'
I get this error:
tail: cannot open '.viminfo' for reading: No such file or directory
tail: no files remaining
ideas?
update
function option
function totprod1log() {
ssh -i file.pub user@host;
cd /path/to/logs;
tail -f $(ls -Art | grep info | tail -n 1);
bash --login;
}
this option simply made me login on aws, but nothign else
the function option didn't work, see update to answer – abbood – 2018-02-10T06:38:50.350
the ugly quoting thing worked though! – abbood – 2018-02-10T06:40:42.923