security,

SCP F5 UCS to a Remote Host Every week

vkosuri vkosuri Follow Jun 27, 2022 · 1 min read
SCP F5 UCS to a Remote Host Every week
Share this

About UCS

A user configuration set (UCS) is a backup file that contains BIG-IP configuration data that can be used to fully restore a BIG-IP system in the event of a failure or Return Materials Authorization (RMA) replacement. More information about UCS

The below script uses expect to input the password.

You need to login into F5 BigIP and update the execute permission to expect file chmod +x scp_f5_ucs.exp

About cron

If you want to execute this script every week place them F5 cron utility save below snippet into a file scp_ucs_f5.scp.exp and place them in this directory /etc/cron.weekly, it will execute Only once per week, at 04:22 on Sunday.

#!/usr/bin/expect -f

# set scp location, user and password
set remote_host "10.1.1.1"
set remote_user "tester"
set remote_path "/backup/F5/"
set password "tester"

# set filename to host+date
set fileName "$env(HOSTNAME)_[timestamp -format %Y%m%d]"

# set expect timeout -1 to wait infinte time
set timeout -1

# spawn bash to run ucs command and scp to remote location using password
spawn bash -c "tmsh save sys ucs $fileName && scp /var/local/ucs/$fileName $remote_user@$remote_host:$remote_path"

expect {
  -re ".*es.*o.*" {
    exp_send "yes\r"
    exp_continue
  }
  -re ".*sword.*" {
    exp_send "$password\r"
  }
}
interact

More information about expect package

You could find code snippets GitHub Gist

Join Newsletter
Get the latest news right in your inbox. We never spam!
vkosuri
Written by vkosuri Follow
Not a native English speaker or writer, Deutsch Learner, love to explore new ideas and document!.