Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:32:25+00:00 2026-06-17T00:32:25+00:00

I need to setup a cron job on multiple servers (all Unix based). For

  • 0

I need to setup a cron job on multiple servers (all Unix based). For this, I have created a script (lets refer to it as script “A”) which sets up the cron job correctly when executed manually. Also, I have uploaded this script to all the target servers with the intention of calling and executing it automatically via another script on another server.

Now, this other server contains the script “B” (as mentioned above) which logs into all the target servers and calls script A in order to automatically setup the cron on all servers.

The problem is, script A is never called and cron is never setup. Script B is an Expect script and here’s the code,

spawn rsync -avz -e ssh $localDir/autodir $username@$ipaddress:$remoteDir
sleep 10

expect {
"assword:" {
    send "$pwd\r"
    sleep 5
    exp_continue
}
expect {
    "@" {
        send "cd /home/$username/autodir/config\r"
        sleep 5
        exp_continue

        expect "@"
        send "./setCron.sh" # NEED TO EXECUTE THIS AT REMOTE SERVER
        sleep 5
        exp_continue
    }
}
"yes/no" {
    send "yes\r"
    set timeout -5
    exp_continue
}
-re $prompt {
    send "\r"
}
timeout {
    exit
}
eof {
    exit
}
}

Basically, I am looking for a general purpose solution to call a script on a remote server without using ssh or public key authentication because I cannot use both of these methods due to some limitations. Hence I tried using Expect but to no success. I could not find the proper solution even after a lot of rummaging. Help needed here!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:32:26+00:00Added an answer on June 17, 2026 at 12:32 am

    Just discovered the solution while tinkering around. Here’s the code,

    spawn rsync -avz -e ssh $localDir/autodir $username@$ipaddress:$remoteDir
    sleep 10
    
    expect {
    "assword:" {
        send "$pwd\r"
        sleep 5
        exp_continue
    }
    timeout {
        exit
    }
    }
    
    spawn ssh $username@$ipaddress
    sleep 10
    
    expect {
    "assword:" {
        send "$pwd\r"
        sleep 5
        send "sh /home/$username/autodir/config/setCron.sh\r"
        sleep 5
        exp_continue
    }
    timeout {
        exit
    }
    }
    

    This logs into all my servers, syncs the file/directories and sets up the cron job. Works like a charm. I had to use ssh in the end though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cron job the executes a PHP script. The cron is setup
I have a PHP script that has been running as a cron job. The
I need to add a cron job thru a script I run to set
I want to setup a cron job (I think this is my best option)
I've setup a Cron job in Google App Engine (Java) and have deployed it
I need to setup ActiveMQ with MySQL which i follow this article http://note19.com/2007/06/23/configure-activemq-with-mysql/ I
I need to setup multiple queues on an exchange. I would like to create
I need to set up a cron job that runs an executable compiled using
I'm running a cron job that executes mysqldump via a PHP script, the dump
I'm trying to setup a cron job which regularly poles my Facebook notification RSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.