Forum Discussion

Dave_Mehlberg's avatar
Dave_Mehlberg
Icon for Nimbostratus rankNimbostratus
Apr 29, 2013

create script in bash that has tmos commands

How do I create a bash script that will run tmos commands and output the results to a file that can be sent to another server via sftp?

 

10 Replies

  • This is actually pretty straight forward. Take a look at the example BASH script monitor at /config/monitors/sample_monitor. This is an example of taking arguments from the GUI monitor (the node and IP), performing some action, and then reporting back ("up" or nothing). If you don't care about monitoring server nodes in your script, then you can just create a BASH script to do what you want it do. You'll use TMSH to get/set whatever you need from the running configuration and an SFTP client is on the box. If you create your script as a monitor and assign it to a "dummy" pool, the BIG-IP will do the job of scheduling it.

     

     

    If you can be more specific with your request we can potentially help you write that script.
  • All I really want to do is output the data from the tmos command 'show sys performance' to a file, then send that file to a server for parsing and displaying.

     

     

    I can't seem to find a way to enter tmsh from a bash script and then run the command...

     

     

    Thank You,

     

     

    Dave

     

  • tmsh -q show sys performance

     

     

    that will run the command with paging disabled. You could write the output to a temp file and then sftp the file to a remote host.

     

     

    I was hoping you could just pipe that to sftp, but it doesn't look like sftp supports reading from a pipe:

     

    http://serverfault.com/questions/400203/how-to-pipe-data-to-sftp-connection

     

     

    Aaron
  • hi Dave,was this successfull from your side? are you able to get show sys performance to file then send that file to a server for parsing and displaying?

     

  • Hi,

    recently I had to use SFTP to store a scheduled backup to a remote server via SFTP.

    The script is continuously executed via cron.

    Two things to consider:

    1. cron settings are not stored in .ucs archive (will not be saved / migrated) 2. known hosts are not stored in .ucs archive (will not be saved / migrated)

    That´s why an additional script is used to update cron and known hosts (pls let me know, if this is required as well).

    Regarding the script below:

    SFTP uses a batch file which is dynamically created each time the script runs. It relies on exporting the own SSH public key to the remote destination. Make sure key based authentication via SSH works for root before running the script.
    ! /bin/bash
    
     save current configuration to /shared/backup/ directory
     ( /shared/backup/ needs to be created in advance )
     sftp archive to remote server
     delete archives older 7 days
     log archive removal to /var/log/ucsdelete
     copy script to /shared/autobackup.sh
     make script executable
       chmod 775 /shared/autobackup.sh
     modify cron (crontab -e) to save config i.e. two times per day
       5 */12 * * * /shared/autobackup.sh
    
    time=`date +%Y%m%d_%H%M`
    unit=`echo "$HOSTNAME" | awk -F '.' '{print $1}'`
    tmsh save /sys ucs /shared/backup/autoarchive_${unit}_${time}.ucs
    cat > /shared/backup/sftpbatch << EOF
    put /shared/backup/autoarchive_${unit}_${time}.ucs /remote/backup/autoarchive_${unit}_${time}.ucs
    EOF
    if sftp -b /shared/backup/sftpbatch root@10.200.200.172
    then
      logger -p local0.notice "0108500:5: Remote config backup success for file /shared/backup/autoarchive_${unit}_${time}.ucs"
    else
      logger -p local0.warning "0108500:4: Remote config backup failed for file /shared/backup/autoarchive_${unit}_${time}.ucs"
    fi
    find /shared/backup/ -name "autoarchive*" -mtime +7 -ls >> /var/log/ucsdelete
    find /shared/backup/ -name "autoarchive*" -mtime +7 -ls -exec rm -f {} \;
    

    Thanks, Stephan

  • Hello,

     

    Hello, when I generate an automatic backup it shows me this error when I execute the script:

     

    Error, invalid characters in UCS file name. The dash, period, forward-slash, plus sign, and underscore are the only special characters allowed.

     

    What is the problem?

     

    Thank's

     

    • Stanislas_Piro2's avatar
      Stanislas_Piro2
      Icon for Cumulonimbus rankCumulonimbus

      Hi,

       

      Please provide the backup script you use!

       

      The only answer I can give with provided info is:

       

      The dash, period, forward-slash, plus sign, and underscore are the only special characters allowed.

       

    • ogozar_275571's avatar
      ogozar_275571
      Icon for Nimbostratus rankNimbostratus
      !/bin/bash

      DATE=

      date "+_%d_%m_%y"
      echo getHostName=$HOSTNAME tmsh save sys ucs $HOSTNAME$DATE cd /var/local/ucs/ ftp -n 192.168.1.2 <

      The test was run in version 12.1.2 build 0.0.249 and there were no problems. But the tests were performed in a cluster with version 12.0.0 bluid 0.0.606 and showed the error mentioned.

      Simplify the script to only: "tmsh save sys ucs backup_test" and showed the same error.