- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- System Administration
- >
- install cron issue
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 06:36 PM - last edited on 05-13-2013 02:29 AM by Maiko-I
05-09-2013 06:36 PM - last edited on 05-13-2013 02:29 AM by Maiko-I
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
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 07:00 PM
05-09-2013 07:00 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 08:57 PM
05-09-2013 08:57 PM
Re: install cron issue
This is linux I am afraid, the $(hostname) doesnt work on it.
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 09:53 PM
05-09-2013 09:53 PM
Re: install cron issue
ssh -n host1 echo '*/10 * * * * /usr/local/script.sh > /logs/output.${HOSTNAME}' >> /tmp/cron-list
HOSTNAME: Undefined variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 10:38 PM
05-09-2013 10:38 PM
Re: install cron issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2013 11:01 PM
05-09-2013 11:01 PM
Re: install cron issue
HOSTNAME: Undefined variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2013 01:08 AM - edited 05-10-2013 06:33 PM
05-10-2013 01:08 AM - edited 05-10-2013 06:33 PM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2013 05:13 PM - edited 05-10-2013 05:14 PM
05-10-2013 05:13 PM - edited 05-10-2013 05:14 PM
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?
- Tags:
- ssh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2013 06:33 PM
05-10-2013 06:33 PM
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.
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP