I need help in BASH

(Artem Fedai) #1

Hi to all i need help in some bash scripting, who can help ?

(Davide Principi) #2

Perhaps it’s quote off-topic but I could help…

(Jose "Martin" Abeleira. AKA Marto) #3

just shoot

(Artem Fedai) #4

i need Bash script that :
a) GO to the Remote Server IP by ssh
b) run on remote server 'some command’
c) check 'uptime’
d) save step B and step C to remote file
e) compress file from step D and push it to the computer from which I run this script

(Davide Principi) #5

If I remember correctly the -c flag in ssh runs commands in a remote shell.

You can pipe the output on your local PC.

(Stefano) #6

ok… this is your solution, now explain your problem :smiley:

(Artem Fedai) #7

Ok i need use scp and ssh -c?!
Next i need bash script to show what service compare with port from /etc/services

(Stefano) #8

can’t understand you, could you explain what are you aiming to?

(Artem Fedai) #9

So i need bash script , when you enter ./service.sh 80 they should give name of service that come in file /etc/services

(Jose "Martin" Abeleira. AKA Marto) #10

echo "Enter the port you want to check"
read port
echo “Enter kind of port tcp/udp"
read proto
grep " “$port”/”$proto /etc/services | awk -F# '{ print $2 }'
if [ $? -eq 1 ]
echo "No results found"

(Jose "Martin" Abeleira. AKA Marto) #11

The problem was that he wanted to grep what was the service
name/description from /etc/services given a port

(JamesMillar) #13

You can create a script with the command you want to run and ‘C’ on the remote server. Run it using SSH and then use SCP to collect the logs from said script.
What commands in addition to uptime are you looking to do?