Admin... by accident!

You may have chosen to be an admin. I didn't!

  • Home
  • FreeBSD
  • GNU/Linux
  • Security
  • Network
  • Virtualization
  • Politics
  • Github
  • Donate
  • Me

What is Expect?

November 19, 2017 by Albert Valbuena

Expect is a handy scripting tool for task automation. You may have never heard of it. I heard about many scripting things before. But one day I needed something simple but didn’t know how to proceed, what would be a good tool for my purpose. The task was simple. Exporting a website content from a managed hosting to a VPS (virtual private server) onto another company in another continent without human intervention. The human intervention part also meant, and this was one of the goals, not having an ssh connection on enduring several long hours, not only to save power on my devices but also just in case my connection went down for whatever the reason. I looked around for a few hours and expect convinced me.

What is expect after all? On my own words it is a tool that allows you to execute tasks a human being will be required to perform them but removing the human from the equation. This is called automation. Is it good or is it bad? Both. I tend to look at it as good since automation releases human attention from tedious tasks and allows us to focus on other things we consider more important and convenient to accomplish.

If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.

How did I use it then? Well… I wrote the expect script so then at a convenient time a cron job would trigger it and perform the task (export all my website data). I had already dumped the databases. All I needed was my content. It was more than one site, since I was hosting for more things than mine. I did some tests with several expect scripts until I nailed it. Editing cron was also something I was familiar with but once you play with it you discover a nice way to arrange tasks and everything becomes logic in your head.

What this script depended on? Basically ssh access which I had.

How was the expect script structured?

Asking to the remote server for an sftp connection
Send the password
Once in give the right command to get the content from the right target
Keep the connection open enough time for the transfer to finish.
Close the connection.

This script will only work if you have previously established an ssh connection to the remote server. Otherwise it will fail since there will be some questions the expect script will not be able to answer. Adapt it to your specific needs. For example in this case the hosting company allowed ssh connections by using passwords. But your use case for a similar scenario may slightly vary. Imagine your hosting company may be using ssh keys only. That’s different and you have to adapt the script to it.

Once you have the script you have to set the cronjob. The easiest way is to do this from a web based administration panel such as Webmin. But of course you can also set this from the terminal. Obviously you will have to install expect into one of the machines involved. In my case it was the destination server since this was the one calling (with the script) to the remote one asking for the data. I was claiming for my beloved articles, pictures, and hours of work. And I did it while I slept, ate and went for a drink. It was automatic.

Use this link to get 100 $ credit at DOcean and support Adminbyaccident.com hosting costs.

Filed Under: How To's, How To's

Recent Posts

  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0
  • How to configure Modsecurity 3 for WordPress on FreeBSD
  • How to configure Apache HTTP with a TLS reverse proxy backend on FreeBSD
  • How to detect a WAF – Web Application Firewall
  • How to install Matomo 4 on FreeBSD
  • How to test SSL/TLS configurations
  • How to configure Apache HTTP as a reverse proxy on FreeBSD
  • How to install Nextcloud on FreeBSD 12
  • How to install ModSecurity 3 on FreeBSD
  • How to replace a disk on a ZFS mirror pool
  • How to install Webmin on FreeBSD 12

Archives

  • February 2023
  • January 2023
  • December 2022
  • April 2022
  • March 2022
  • October 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • January 2018
  • November 2017
  • April 2017

RSS Admin… by accident!

  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0

Copyright © 2023 · Magazine Pro Theme on Genesis Framework · WordPress · Log in