Reputation: 243
I am writing a bash script to scan multiple linux machines for a line to see if it meets standards for the organization:
grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin
I am doing this using the ssh command like this:
ssh -q <<HOSTNAME>> grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin
the problem is as follows:
sudo su -
manually on each box. (I want to automate this./sbin/sulogin
is a root only file. and cannot see the file under any other user.how do I include sudo su -
into the ssh command to ssh into the server, then sudo su -
, then scan the file I need?
Thanks.
Upvotes: 0
Views: 2532
Reputation: 983
Try this. user has to be part of sudoers.
ssh -t user@hostname 'sudo grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin'
Upvotes: 1