CodeShare
Have some code. Share some code.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner
MalliKosuri
F5 Employee
F5 Employee
Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.

Article K175: Transferring files to or from an F5 system discuss the secure transfer of files, whereas almost all the remote host machine will have password-based authentication or public key authentication, In this article demonstrates using the remote host using the password to transfer UCS/any other files. The below expect script demonstrates.

 

#!/usr/bin/expect -f

set timeout -1

# set fileName as hostname
set fileName "[exec /bin/hostname]-[exec date +%d%b%Y]"

######################################
# The below involves multiple steps
# 1. spawn a local shell
# 2. save ucs file to /var/local/ucs
# 3. Do scp to remote host
# 4. remove the ucs file
# 5. Accept Yes
# 6. Provide password
#######################################
spawn bash -c "tmsh save sys ucs $fileName && scp /var/local/ucs/$fileName.ucs root@10.218.49.137:/var/local/ && rm -rf /var/local/ucs/$fileName.ucs"
expect {
  -re ".*es.*o.*" {
    exp_send "yes\r"
    exp_continue
  }
  -re ".*sword.*" {
    exp_send "default\r"
  }
}

expect eof

 

Save the script into separate file ``scp_ucs.sh`` and chang execution permission of the script ``chmod +x scp_ucs.sh``

If you want to execute the script periodically add the script to the cron utility on the BIG-IP system that will execute based on your configuration.

Comments

Also the F5 REST API can be used for some file tasks but with some limitations as mentioned in https://support.f5.com/csp/article/K41763344 .

Version history
Last update:
‎31-Jan-2023 03:23
Updated by:
Contributors