- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: ssh and crontab problem, variable expansion
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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.