1. Forum Rules (PLEASE CLICK HERE TO READ BEFORE POSTING) Click the link to access ADSM.ORG Acceptable Use Policy and forum rules which should be observed when using this website. Violators may be banned from this website. This message will disappear after you have made at least 12 posts. Thank you for your cooperation.

How to use IF statement along with day of week in TSM script?

Discussion in 'Scripting' started by TMan, Jul 31, 2012.

  1. TMan

    TMan New Member

    Joined:
    Mar 10, 2006
    Messages:
    4
    Likes Received:
    0
    Occupation:
    TSM Admin + SAN Admin
    Location:
    Austin, TX
    Hey all!

    I have recently migrated from an AIX TSM instance to Windows TSM. I'm now converting all my AIX scripts to TSM scripts where possible, but can't find a lot of documentation on how to apply logic within TSM scripts.

    So, on my daily maintenance script, I'd like to backup storage pools, run a DB backup, run a prepare and then eject DRM tapes on weekdays. Something like:

    if (??day of week is Saturday or Sunday??) goto expire
    q drm t* wherestate=mountable > /path/file
    move drm t* wherestate=mountable remove=bulk tostate=vault
    expire: expi i
    exit

    Can anyone show how to accomplish the ??day of week is Saturday or Sunday?? part of this? Any pointers to better docs/guides for TSM scripting would also be much appreciated!

    Otherwise, I figure I'll just have to have a script scheduled for Mon-Fri and a script without the DRM statements scheduled for Sat-Sun.

    Thanks in advance,
    TMan
     
  2.  
  3. chad_small

    chad_small Moderator

    Joined:
    Dec 17, 2002
    Messages:
    2,207
    Likes Received:
    44
    Occupation:
    AIX/SAN/TSM
    Location:
    Gilbert, AZ
    TSM scripts have limited logic processing. It would be easier to create the two separate scripts and schedule them accordingly.
     
    TMan likes this.
  4. rmazzon

    rmazzon Senior Member

    Joined:
    Dec 6, 2004
    Messages:
    207
    Likes Received:
    17
    Occupation:
    TSM Managed Services Lead
    Location:
    NC
    TSM scripts are very limited but you can do the following with your example (days of week start with Sunday as 1)

    select server_name from status where dayofweek(current_timestamp) in (7,1)
    if(rc_ok) goto expire
    q drm t* wherestate=mountable > /path/file
    move drm t* wherestate=mountable remove=bulk tostate=vault
    expire: expi i
    exit

    More generally you can do stuff like this

    select server_name from status where dayofweek(current_timestamp)=1
    if(rc_ok) goto Sunday
    select server_name from status where dayofweek(current_timestamp)=2
    if(rc_ok) goto Monday
    select server_name from status where dayofweek(current_timestamp)=3
    if(rc_ok) goto Tuesday
    ...
    etc etc etc
    select server_name from status where dayofweek(current_timestamp)=7
    if(rc_ok) goto Saturday
    /* technically next line not needed but ... */
    goto Exit
    Monday:
    ....
    goto Exit
    Tuesday:
    ...
    goto Exit

    etc etc etc
    Exit:
    exit

    I like to use constructs like this to get windows within a day
    select server_name from status where hour(current_time) not in (12,13,14,15)
    if(rc_notfound) goto exit
    ...

    or to check if a process is already running before starting
    select * from processes where process='Reclaim Storage Pool' and status like '%TAPEPOOL%'
    if(rc_notfound) backup stg mesgdisk mesgcopy maxpr=$1

    I don't have any docs or links though, just trial and error. And they can get pretty ugly so moderation is the key. And you might want to use calls to scripts using the run command to keep any single script reasonable to read.
     
    mguery and TMan like this.
  5. TMan

    TMan New Member

    Joined:
    Mar 10, 2006
    Messages:
    4
    Likes Received:
    0
    Occupation:
    TSM Admin + SAN Admin
    Location:
    Austin, TX
    Great example rmazzon - Thanks!

    In reading about the IF in TSM, it does look to be really limited. :( That really hurts my feelings coming from AIX/kornshell scripting.

    The extra examples are also appreciated. My previous script for starting reclamation would get the current time and do a simple subtraction to give "recl stg" a duration. But with the example you gave to see if a process is running, I'll just schedule the reclamation to start, have it check for processes which _should_ be finished (like stg pool backups or DB backups) and run for a predetermined amount of time.

    Off to experiment!

    Thanks again,
    TMan
     

Share This Page