1

I must connect to server every day by ssh, and I made a script to display logs.

This is my code:

#!/bin/bash

A=`date +%Y`
M=`date +%m`
D=`date +%d`

gnome-terminal --geometry=82x11 \
--tab --title "NAMEServer" -e "sshpass -p P4ssw0rd ssh USER@123.456.789.10 'tail -f /opt/logs/example.$A-$M-$D.log'" \
--tab --title "NAMEServer" -e "sshpass -p P4ssw0rd ssh USER@123.456.789.10 'tail -f /opt/logs/example.$A-$M-$D.log'"

But if I try filter a words with grep, not working. Example:

-e "sshpass -p P4ssw0rd ssh USAER@123.456.789.10 'tail -f /opt/logs/example.$A-$M-$D.log | grep 'not fetch''" \

or

-e "sshpass -p P4ssw0rd ssh USAER@123.456.789.10 'cat /opt/logs/exaple.log | grep 'any problem''" \

I think the problem is the quotation marks, but, which use?, I tried with ´´ ' ' " ".

1

You are correct, it is your quotation marks. You are nesting single quotes without escaping. Try this:

-e "sshpass -p P4ssw0rd ssh USAER@123.456.789.10 'cat /opt/logs/exaple.log | grep \'any problem\''" \
  • thanks @forquare, but I tried it, or assign a variable and not working. – ymk369 Aug 28 '15 at 1:36
0

Try adding bash at the end like:

e "sshpass -p P4ssw0rd ssh USAER@123.456.789.10 'tail -f /opt/logs/example.$A-$M-$D.log | grep 'not fetch'; bash' " \

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.