Awk On Remote Server

Hi,

I am running awk command on remote server it is not giving desired results but if i run the same command on local server. it works as expected. Can anybody help me to resolve this and let me know the logic behind this?

Remote server

# ssh test 'free -g | grep Mem | awk -F " " '{ print $2 }''
awk: cmd. line:1: {
awk: cmd. line:1: ^ unexpected newline or end of string

local server
# free -g | grep Mem | awk -F " " '{ print $2 }'
31


Thanks in advance.


Similar Content



What Ftp Server Is Running

in my RHEL 4 server , I want to know what ftp server is running but can't find it.

I tried "ps -ef |grep ftp" but no output , chkconfig --list |grep ftp also no output related to ftp , /etc/rc.d/init.d can't find ftp service , ftp localhost is not allow .

when use FileZilla to connect it , it is ok , the ftp should be running , I tried to use "ps -ef |grep ftp" , it pops the following output , would advise what ftp server is running in server ? thanks

Code:
edp 11027 11026  0 12:39 ?        00:00:00 tcsh -c /usr/libexec/openssh/sftp-server
edp 11037 11027  0 12:39 ?        00:00:00 /usr/libexec/openssh/sftp-server
user   11050  7747  0 12:48 pts/2    00:00:00 grep ftp

Bash Scrip Running On Remote Server

This is my script and the syntax to run this script is give ip and next will be the file or script you want to perform on remote server



#!/bin/bash

# The private key used to identify this machine
IDENTITY_KEY=/home/adnew.pem

syntax()
{
echo "Syntax: Ec2.sh server_ip scriptFile]"
echo "For example: ./Ec2.sh server_ip scriptFile"
exit 1
}

if [ $# -ne 2 ]
then
echo not enough arguments
syntax
fi


echo "Running script $2 on $1"
ssh -ttq -i $IDENTITY_KEY ec2-user@$1 sudo -i 'bash -s' < $2
exit
exit
echo "Done"



on script file i have give for testing

touch /root/test
ls /root/test
exit
exit

it makes the file but do not show the ls output by giving error


tcgetattr: Inappropriate ioctl for device

exit


what I have to do ??

How To Copy File From Remote Host To Local Host Then Delete From Remote Host

I have an expect script to SSH to a remote host and obtain some user inputs and information about the server/network configuration. The responses are saved in a text file that I then need to copy to my local host so that I can read the lines into variables for use in the parent shell script.

Is there a way to do this without needing to enter the username and password for the local host to use function scp? I have tried the following in my expect script to no avail:
Code:
spawn scp $usr@$host:$flnm .
expect {
	-re "(.*)assword:" { 
		send -s "$pswd\r"
	}
}

I have also tried to directly scp the file and enter the username and password to try to debug the issue, and that doesn't work either:
Code:
spawn scp file.txt user@host:file.txt
expect {
	-re "(.*)assword:" {
		send -s "password\r"
	}
	"you sure you want to continue connecting" {
		send -s "yes\r"
		exp_continue
	}
}

In both scenarios I have used exp_internal 1, and there are no errors. But I do not end up with the file on my local host.

Following the copy, I would like to delete the file from the remote host. Any suggestions on how to accomplish this?

Regular Expression In Expect Script To Prevent Printing To Screen

Hello, I have an expect script where I ssh to a remote host to determine the network configuration and get from the user the network interface card that should be used. From their response, I determine the subnet mask and save the information to a text file that is later transmitted back to my local host. This is all so that I can set up virtual IP aliasing and verify that the physical IP address of the local and remote host are on the same subnet prior to continuing with the setup. I am running the script on Linux, with expect version 5.45.

The code itelf works just fine, but I'm having some issues with how it displays on the screen. As you'll see below in the example, the default system prompt displays, as does the user input command that I'm sending to the shell from the expect script.

Is there a regular expression or something that I can write to prevent the prompt and command that I'm sending from printing to the screen? I know that it should be suppressed if I have an expect command following the Code:
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r

command, but everything I have tried for strings and regular expressions to expect causes the netstat -rn output to not show up all of a sudden. I'm new to expect, so I'm not really sure why this is happening.

I would really appreciate any help/suggestions. Thanks for your time!

Part of the Script Code:
Code:
expect {
   -re $prompt {   ;# Send individual commands and get user input
        set timeout -1
        
        # Get partner hostname and put in vipsetup.txt file
        send -s "hostname > vipsetup.txt\r"  
        expect -re $prompt
        
        # Display the network routing info for the user and prompt for 
        # network interface card number
        send -s "print \"The network routing table for the $ptner server is displayed below:\n\" ; netstat -rn \r"
        
        expect -re "\r(.*):\r"
        send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r"
        interact "\r" return    ;# Wait for user input from read command
        send -- "\r"
        send -s "echo \$n_card >> vipsetup.txt\r"  
        
        # Obtain subnet mask information for partner based on network 
        # interface card number being used
        send -s "msk=\$(cat /etc/sysconfig/network-scripts/ifcfg-\$n_card | grep NETMASK)\r"
        send -s "msk=\$(echo \${msk#NETMASK=})\r"
        send -s "echo \$msk >> vipsetup.txt\r"
    }
    timeout {
        send_user "Connection to host $hostip timed out."
        exit 6 
    }
    eof {
        send_user "Connection to host $hostip failed."
        exit
    }
}


Script Output:
Code:
The network routing table for the PRIMARY server is displayed below:
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.105.65.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         10.105.65.1     0.0.0.0         UG        0 0          0 eth0
 [root@remotehost root]$
[root@remotehost root]$ ber for this server (i.e. eth0):   '              < 
Enter the network interface card number for this server (i.e. eth0):   eth0

Using Awk Print

Hi Linux Guru's

need some a little help regarding on the jboss command that will validate. The command should only echo either "jboss7" or "jboss4"


however in our jboss7 we got also jboss7modules running and it should not be there from the output

[pogi.ako@server2 ~]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}'
jboss7
jbossmodules


using with |tail -1 | head -1
[lemuel.luna@server2 ~]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}' |tail -1 | head -1
jbossmodules


but from other servers I see it has different approach

[pogi.ako@server1 bin]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}'
jbossmodules
jboss7


[pogi.ako@server1 bin]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}' |tail -1 | head -1
jboss7


I'm trying to achieve here on on not to include jbossmodules from the output

How To Change IP Address Of Remote Machine?

Hi all

This is bothering me too much, please tell me how to change IP address of remote machine while using ssh successfully.

I follow these steps:
1. connect to remote server using 'ssh root@server'
2. Edit '/etc/sysconfig/network-scripts/ifcfg-eth0' file
3. issue 'service network restart' command... (at this point ssh connection gets hanged)
4. Break from hanged ssh connection (<ENTER>~.)
5. Wait for some time to let service restart
6. Then finally, ssh with new ip address.

All is fine, but last time, i did something wrong while assigning new IP address, and after service restart, remote server didn't get new ip address - and now i cant connect to remote server.

Fortunately, i had a friend there, who helped me correct the problem so that i can connect again.

But what to do when there is no one to help? Is there other way i should approach this problem?

Thanks

Rsync Question

Hey guys, I have rsync going to another remote server
it works good, however, lets say server A deleted a directory, server B wont sync up to it.

if I were to add a directory to Server A, then server B will add it as well. so server B is just not deleting stuff.

is there a proper rsync command i can use ?

would rsync -xzva --delete /src /dst delete everything and start the rsync from scratch? or is there another way to do this

Libreoffice Cannot Find Network Printer, Offers Only (non-existent) Generic Printer

Arch linux, lxdm/lxde, recent installation, feeling I must be doing something stupid, would be glad to be guided!

I have a Brother HL-2030 printer connected to a Raspberry Pi as a print server, CUPS setup, with sharing turned on. Other machines in the household, and indeed other OS's on the machine I'm writing on, print trouble-free to this printer.

On *this* desktop machine, (with libcups installed,) other programs print trouble-free. Firefox, Thunderbird, geany and evince all detect the presence of the network printer, and work as expected.

It's just Libreoffice that does not. This is true both of libreoffice-fresh and libreoffice-still, and it is true for all the components (write, draw, calc etc).

Libreoffice *does* find the network printer from other OS's that I play with; I have Puppy and Mint on the same machine, but those installs of Libreoffice are obviously different/earlier versions (nor do I feel like upgrading them in the circumstances!)

In this context, though, the Libreoffice "File>Printer settings..." menu offers me only a "Generic Printer" (whose properties and options I can edit). If I ask Libreoffice to print to this generic printer, it reports no failure, but that task just seems to disappear into thin air.

On the Pi server, /var/log/cups/ offers

Code:
# extract from /var/log/cups/access_log
# [...snip]
192.168.2.2 - - [22/Jan/2015:18:21:21 +0000] "POST / HTTP/1.1" 200 566 CUPS-Get-Printers server-error-version-not-supported
192.168.2.2 - - [22/Jan/2015:18:21:21 +0000] "POST /printers/Brother_HL-2030_series HTTP/1.1" 200 15824 Print-Job successful-ok
# the above line logs a successful print from geany
192.168.2.2 - - [22/Jan/2015:18:26:40 +0000] "POST / HTTP/1.1" 200 673 CUPS-Get-Default server-error-version-not-supported


# extract of /var/log/cups/error_log
# [...snip]
E [22/Jan/2015:18:21:20 +0000] Returning IPP server-error-version-not-supported for CUPS-Get-Printers (no URI) from 192.168.2.2
E [22/Jan/2015:18:21:20 +0000] Returning IPP server-error-version-not-supported for CUPS-Get-Printers (no URI) from 192.168.2.2
E [22/Jan/2015:18:21:21 +0000] Returning IPP server-error-version-not-supported for CUPS-Get-Printers (no URI) from 192.168.2.2
E [22/Jan/2015:18:26:40 +0000] Returning IPP server-error-version-not-supported for CUPS-Get-Default (no URI) from 192.168.2.2

I really think I must be doing something very stupid and newbie-ish!

Disk Is Not Getting Detected After Run The Scsi Command

Hi

RHEL 6.4 (64 Bit) is running as a Virutal Machine in a VCenter Server 5.5
As per our request, Vmware team added 500GB of disk space to this VM. Disk is not visible in "fdisk -l" after run the following command/script, but the new disk could be seen from the "multipath -l" command.

for i in `ls -ld /sys/class/scsi_host/host* | awk '{print $9}' `
do
echo "- - -" > $i/scan
done

Could someone clarify why it is not visible in "fdisk -l" output?

Difference In Outputs When Using TLS1

Hello All,

I am rookie when it comes to security protocols and I am learning this as part of my job responsibilities.

Recently our Application started implementing TLSv1.2 and here are some questions that I have from my observations.

1st the term ciphers, keys, certs are all very confusing to however I started to get some understanding of these as I am reading a lot of stuff.
Now, my application is running on "X" server and only accepts TLS1.X connections since the i use java 7 where ssl2Hello is disabled

now from Server "A" when I run cmd: openssl s_client -tls1 -host xxx -port yyyy
I get back a response in which I see a line
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-SHA
the openssl version on server A is: 1.0

when I run the same command from another server "B" I get a response in which the line says:
New, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHA
the openssl version on server B is: 0.9

My understanding of cipher was something that is enforced by the application server "X" and not by the client that is making the call. Is that a wrong understanding ?
And how can I find out what type of cipher is being enforced by the server "X" when someone makes a call to it.

Anyone who can help me understand why the difference how this entire stuff operates.
Help much appreciated.