Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm in a unix environment where I'm using check_by_ssh to execute Nagios plug-ins. A few hosts have a different unix account to which Nagios needs to ssh into to run the plug-ins. I pass the account name with -l like this:

command_line    $USER1$/check_by_ssh -p 22 \
   -H $HOSTADDRESS$ -l <user> -i /home/nagios/.ssh/$HOSTNAME$ -C '<plug-in path>'

For the machines that have a different unix account is there a way to not have to double all the command definitions e.g. replacing -l nagios with -l user1 ?

I was hoping there was a way to pass the username in the host definition to say this set of hosts should login with user1 and this other set of hosts should use user2.

Any help is appreciated.


share|improve this question
up vote 1 down vote accepted

Note: I haven't tested this code.

That said, I would probably define an alternate check in commands.cfg with something along the lines of:

# Check by SSH for hosts with different account

command_line    $USER1$/check_by_ssh_alt -p 22 \
   -H $HOSTADDRESS$ -l $ARG1$ -i /home/nagios/.ssh/$HOSTNAME$ -C '<plug-in path>'

And then invoke it with something like:

define service{
        use                     generic-service
        hostgroup_name          hostgroup_1
        service_description     Some Check by SSH
        contacts                hostgroup_1_admins
        notification_options    w,c,r
        notification_period     24x7
        notification_interval   0
        check_command           check_ssh_alt!user1

Good luck!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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