ocs_prerun - How can I set a variable for the ocs_live_run command ?

polishm
2014-02-25
2014-03-06
  • polishm

    polishm - 2014-02-25

    What I need:

    ocs_prerun="target=/dev/sdb"
    ocs_live_run="ocs-live-restore restoredisk $target"

    I have tried ocs_prerun="source myscript.sh" (using sudo, the '.', etc.). Why won't ocs_prerun accept 'souce' !!!! Works fine from commandline after the script runs.

    Note: I already have a custom script built into the filesystem.squashfs that works perfectly. Didn't imagine setting an environment variable would be so hard. I have to leave the target variable in syslinux.cfg for reasons not important here, so I can't 'just put the restore disk command in this same script'. I already had it that way and was asked to take it out.

     
  • Steven Shiau

    Steven Shiau - 2014-02-25

    That's a good question. We will try to make that in the future.
    For the time being, there is a workaround for you:
    1. Write your variable to a temp config file, e.g. /tmp/my-ocs.cfg
    2. In your customized script, add a line to load the variable:
    [ -e "/tmp/my-ocs.cfg" ] && . /tmp/my-ocs.cfg

    Steven.

     
  • polishm

    polishm - 2014-02-25

    ** RESOLVED ***

    Thank you Steven for the quick reply!

    The workaround you suggested worked:

    In my custom script, I added:

    sudo echo "target="$target > /scripts/tmpfile
    . /scripts/tmpfile

    Now ocs_live_run can 'see' $target in its environment.

    Thanks again.

     
  • polishm

    polishm - 2014-02-25

    * OOPS.. My Mistake NOT Resolved (yet) **

    I jumped the gun and only thought it was working. It does create the tmpfile with the proper value, and then presumably sources it, but any subsequent attempt, after the script completes, to use or echo $target only returns an empty string.

    After NOT being able to get any commands like 'echo ${!target}' or 'eval ${target}' to work and help troubleshoot, I think I'm going to try just putting my code in the ocs-sr script itself!

     
  • polishm

    polishm - 2014-02-25

    Follow up:

    Simply putting my 'pre-run script logic' into the ocs-sr script directly is an easy work-around.

    * Resolved for now. Moving on...

     
  • Steven Shiau

    Steven Shiau - 2014-03-06

    :)
    Enjoy!

    Steven.

     

Log in to post a comment.