1748092 Members
6025 Online
108758 Solutions
New Discussion

install cron issue

 
allanm77
Frequent Advisor

install cron issue

ssh -n host1 "crontab << */10 * * * * /usr/local/script.sh > /logs/output.${HOSTNAME}"

 

I have around 100 hosts and need to populate this cron entry on them but the variable $HOSTNAME is expanding to the name of the admin box I am trying to deploy from.

 

How can I fix this. Please advise.

 

Thanks,

Allan.

 

 

P.S. This thread has been moevd from HP-UX > Languages and Scripting to Linux > sysadmin - Hp Forums Moderator

 

 

 

 

 

8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: install cron issue

I would use $(hostname) rather that ${HOSTNAME}.  $(hostname) will run the hostname command on the serve that the script runs on. 

 

Also, if you are deploying this to HP-UX servers, the */10 syntax will not work.  That is Linux ONLY syntax.  If you want the script to run every 10 minutes in HP-UX you need to specify 0,10,20,30,40,50 for the minutes.

allanm77
Frequent Advisor

Re: install cron issue

This is linux I am afraid, the $(hostname) doesnt work on it.

 

Thanks,

Allan.

allanm77
Frequent Advisor

Re: install cron issue

even with single quotes I am getting -

ssh -n host1 echo '*/10 * * * * /usr/local/script.sh > /logs/output.${HOSTNAME}' >> /tmp/cron-list

HOSTNAME: Undefined variable.
allanm77
Frequent Advisor

Re: install cron issue

Its also not liking the redirection, I am really dead in water, please help!
allanm77
Frequent Advisor

Re: install cron issue

ssh -n user@host1 "echo */10 * * * * /script.sh '>' /logs/output.\$HOSTNAME '>' /tmp/cron-list"

HOSTNAME: Undefined variable.
Dennis Handly
Acclaimed Contributor

Re: ssh and crontab problem, variable expansion

>the variable $HOSTNAME is expanding to the name of the admin box I am trying to deploy from.

 

Then you need to use single quotes:

ssh -n host1 'crontab << */10 * * * * /usr/local/script.sh > /logs/output.${HOSTNAME}'

Also, I assume this << syntax is some bashism?  I guess it isn't.  You would need to set up a here doc.

 

If single quotes doesn't work, it's because $HOSTNAME isn't defined by default.

So you could do this:

ssh -n user@host1 "echo '*/10 * * * * /script.sh > /logs/output.host1' | crontab"

allanm77
Frequent Advisor

Re: install cron issue, variable expansion

Thanks Dennis that worked though I figured out the solution before I saw your reply.

Another issue I wanted to solve is that  I dont have sshkeyless setup to the hosts and dont have expect installed on the admin box, how do I remote ssh without(or automatically) feeding in the password each time for all 100 hosts?

Dennis Handly
Acclaimed Contributor

Re: ssh and crontab problem, variable expansion

>I don't have sshkeyless setup to the hosts

 

(Did you mean password less?)

I would spend time setting this up so you don't have to do it again.

(Unless you have some management or security reason for not doing it.)-:

 

>don't have expect installed on the admin box, how do I remote ssh without (or automatically) feeding in the password each time for all 100 hosts?

 

Well that's what ssh passwordless is for.

Without expect, I'm not sure there is any other way.