CRONTAB

  • Creator
    Topic
  • #115684
    Stewart
    Participant

    I have a script that calls another script to transfer files to SFTP. It works correctly if I run manual but not with crontab.  It will not call the commands from this program using crontab.  Any idea what would cause this?

    #!/opt/cloverleaf/cis19.1/integrator/tcl/bin/expect -f

Viewing 6 reply threads
  • Author
    Replies
    • #115685
      Stewart
      Participant

      adding email notifications

    • #115690
      David Barr
      Participant

      You probably don’t have LD_LIBRARY_PATH and TCL_LIBRARY set to the right values. I think these are usually set up by the “setroot” command which is called from your login scripts. You may need to make a shell script that calls your expect script, and the shell script can set the environment before calling the script.

      • #121229
        Keith McLeod
        Participant

        I have a new install on Red Hat Enterprise Linux release 8.5 (Ootpa).  I have worked through several issues regarding LD_LIBRARY_PATH by modifying the environment in .profile.local.end for commands such as scp, sftp, rsync and now mail.  I received the following error prior to the modification: mail: symbol lookup error: mail: undefined symbol: SSLv3_client_method, version OPENSSL_1_1_0.

        I added to .profile.local.end and this seemed to resolve from the command line.:

        function mail {
        if [[ -n “$HCIROOT” && -n “$CL_INSTALL_DIR” ]]; then
        clinstalldir=$CL_INSTALL_DIR
        hcisite=$HCISITE
        hciroot=$HCIROOT
        setroot -clear
        /usr/bin/mail “$@”
        export CL_INSTALL_DIR=$clinstalldir
        setroot $hciroot $hcisite
        else
        /usr/bin/mail “$@”
        fi
        }

        This works for using mail at the command line, however inside many of my notification tcl scripts I have code like:

        set sm [open “| mail -s \”${client} – [string toupper $HciSite]: [string toupper $thdName] Not showing a Connection for [expr $downtime / 60] minutes.\” -c ie_mail,${systemName}_mail -r $fromAddress $mailAddress” w]
        puts $sm $assign_to
        puts $sm $priority
        puts $sm $contact
        puts $sm ${client_id}
        puts $sm $description

        close $sm

        This brings me back to the symbol lookup error.  Any thoughts on this???

         

    • #115702
      Peter Heggie
      Participant

      What Dave said. Cron does not have a normal user context associated with it, so many of the environment variables (not just Cloverleaf’s variables, but also ‘normal’ user variables) are not set.

      Depending on whether you are issuing cloverleaf commands or just running UNIX commands that need the HCI user’s context, you could use one of these two styles:

      1. with no Cloverleaf commands:

      05 03 * * * setroot /hci/cis19.1/integrator; . cronpath ; mediquant_to_epsi >> $CRONLOGS/mediquant_to_epsi.log 2>&1

      • where “mediquant_to_epsi” is the application script

      2. with Cloverleaf commands:

      30 00 * * * setroot /hci/cis19.1/integrator; /usr/bin/ksh -c ‘eval /hci/cis19.1/integrator/sbin/hcisetenv -root ksh /hci/cis19.1/integrator soabatprd;. cronpath ; soarian_to_pcp_edchart_fax_stop >> $CRONLOGS/soarian_to_pcp_edchart_fax_stop.log 2>&1’

      • where “soarian_to_pcp_edchart_fax_stop” is the application script

      fyi “. cronpath” will execute a proc called cronpath which sets additional environment variables (like $CRONLOGS – which resolves to a directory name). Using the “dot space name” syntax means execute that named script and apply the results to the current environment instead of a child environment.

      Peter Heggie

    • #115712
      Stewart
      Participant

      This is the crontab setting.  I tried setting the environment variables from env output before the script1 was called but no luck.  I also tried setting these in /etc/crontab.

      0,10,20,30,40,50 * * * *  /home/hci/scripts/dinh_inc_SCRIPT2.sh >> /home/hci/scripts/logs/ftp_dinh_inc.log

      This is the section of script2 which calls script1 which is responsible for uploading the files.  I’ve been able to write to a log file from the called script before and after the commands but the commands are ignored.  So the script was getting called but the commands aren’t.

      sleep 3
      $home/scripts/dinh_inc_SCRIPT1.sh >> $logfile
      FTP_ERROR_MSG=”Failure”

      #!/opt/cloverleaf/cis19.1/integrator/tcl/bin/expect -f

      set timeout 120
      log_file “/home/hci/scripts/logs/ahmedgresftp.log”
      send_log — “####-Starting SFTP script – [exec date] \n”
      send_log — “Today’s date:[exec date] \n”
      send_log — “Downloading files through sftp \n”
      spawn sftp name@address

       

    • #115715
      Robert Kersemakers
      Participant

      What we used to do with cron was first switch the user to ‘hci’ before executing the cron-script. This way all environment variables were set correctly:

      00 12 * * 6 su – hci -c “/cldata/scripts/weekly_housekeeping_cloverleaf” > /dev/null 2>&1

       

      Nowadays we do something different by first calling a different script, for ex.:

      55 23 * * * /home/hci/sethcienv daily_housekeeping_cloverleaf > /cldata/scripts/daily_housekeeping_cloverleaf.log 2>&1

      The script ‘sethcenv’ looks like this:

      if [[ -d /prod/cloverleaf/sites62 ]]
      then
      . /etc/profile
      . /home/hci/.profile
      echo “+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”
      $*
      fi
      exit 0

      It first checks whether the server the cron is running is the active server (we have an active/passive high-availability setup). If this is the case the environments are set after which the required scripts are run.

      Hope this helps.

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

    • #115722
      Stewart
      Participant

      Thanks for all the suggestions.  I got this resolved by reviewing the mail messages in /var/spool/mail/hci.  First error stated it couldn’t locate the expect file, once this was resolved by placing SHELL and PATH at the top of crontab -e it generated another error.  The second error was that it couldn’t locate the shared libraries so I placed the TCL_LIBRARY and LD_LIBRARY output from env below PATH in crontab -e.  I added the following to the top of the crontab.

      SHELL=/bin/sh
      PATH=/opt/cloverleaf/cis19.1/integrator/prod_adt/bin:/opt/cloverleaf/cis19.1/integrator/prod_adt/scripts:/opt/cloverleaf/cis19.1/integrator/prod_master/bin:/opt/cloverleaf/cis19.1/integrator/prod_master/scripts:/opt/cloverleaf/cis19.1/integrator/bin:/opt/cloverleaf/cis19.1/integrator/contrib:/opt/cloverleaf/cis19.1/integrator/sbin:/opt/cloverleaf/cis19.1/integrator/dbms/bin:/opt/cloverleaf/cis19.1/integrator/tcl/bin:/opt/cloverleaf/cis19.1/integrator/clgui/bin:/opt/cloverleaf/cis19.1/integrator/clgui/java/bin:/opt/cloverleaf/cis19.1/integrator/usercmds:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/hci/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/local/scripts:/bin:/home/hci/bin
      TCL_LIBRARY=/opt/cloverleaf/cis19.1/integrator/tcl/lib/tcl8.6
      LD_LIBRARY_PATH=/opt/cloverleaf/cis19.1/integrator/clgui/java/lib/amd64:/opt/cloverleaf/cis19.1/integrator/clgui/java/lib/amd64/server:/opt/cloverleaf/cis19.1/integrator/lib:/opt/cloverleaf/cis19.1/integrator/bin:/opt/cloverleaf/cis19.1/integrator/tcl/lib:/opt/cloverleaf/cis19.1/integrator/dbms/lib:/usr/lib:/lib:/shlib:/usr/shlib:/opt/cloverleaf/cis19.1/integrator/lib/perl5/5.22.0/x86_64-linux/CORE:/opt/cloverleaf/cis6.2/lib/

    • #121236
      Rob Lindsey
      Participant

      This is how we do it with our 20.1 environment using RHEL

      18,48 * * * * source /home/hci/.profile ; /hci/cloverleaf/scripts/export_interface_info_tables_to_web_page_v3.tcl >> /info/logs/export_interface_info_tables_to_web_page_v3_$(date +\%Y\%m\%d).log 2>&1

      The source command pulls in the profile which makes sure that all of the Libraries are set correctly for our environment.

      Rob

Viewing 6 reply threads
  • You must be logged in to reply to this topic.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10