1

I have a script querying a remote server based on user input and looks for the last modified date of a file. It works, however, contained in the file is a string that I need to have displayed as well and everything I've tried has been for naught. I would really appreciate any help.

Script

echo "Input server name:"
read server
echo "Input user:"
read user

ssh $server "find /home/  -maxdepth 2 -name .lastlogin | xargs -l -I{} bash -c '{
stat -c \"User: %U Last Login : %y\" {} | cut -c -47 |grep $user; 
}'"

Current Sample Output

User: owner Last Login : 2014-07-24 15:05:39

I need this output to include the contents of this file, .lastlogin, which happens to be an IP address.

Desired Sample Output

User: owner Last Login : 2014-07-24 15:05:39 From: 172.0.0.1
0

2 Answers 2

0

Ended up doing this, worked great.

echo "Server name:"
read server
echo "Search for user:"
read user

OUTPUT1=$(ssh $server "find /home/$user/.lastlogin | xargs -l -I{} bash -c '{
stat -c \"User: %U Last Login : %y\" {} | cut -c -47;
}'")

OUTPUT2=$(ssh $server "cat /home/$user/.lastlogin")

echo "$OUTPUT1 From: $OUTPUT2"
exit

Output:

User: owner Last Login : 2014-07-24 15:05:39 From: 172.0.0.1
0

Very simple:

ssh $server "readlink -f /home/$user/.lastlogin | \
    xargs -l -I{} bash -c '{
      stat -c \"User: %U Last Login : %y\" {} | cut -c -47 | grep $user;
      echo -n \"From: \" ; cat {} ; echo ; 
    }'"

I would use readlink -f instead of find.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .