Audience

Learn how to execute a script to start an application once the Scanner Management Solution (SMS) execution is completed, as well as starting an application via a script. This blog applies to both the Zebra Scanner Management Solution, and the Zebra Barcode Scanner SDK for Linux. 

  Guide

  1. Open the terminal and navigate to the directory where you want to create the script.
  2. Create a file with .sh extension.
  3. Write the script in the file using an editor.
  4. Make the script executable with this command: 
     chmod +x <fileName>

    5. Run the script using this command: 

./<fileName>
NOTE In the last step, mention the path of the script if your script is in another directory.

 

   Write the script using the sample code block or snippets below: 
 
   1. Start the CoreScanner service. 
   

start_coreScanner_driver () {
    #Start CoreScanner driver
   # :NOTE: different systems does start/stop/status/restart corescanner deamon   #
   # in different way. Some are using systemD and some are using systemV.         #
   # First we have to check whether system is supporting systemV or systemD.      #
   echo "Starting CoreScanner service." 
   which systemctl 2&> /dev/null
   if [ "$?" -ne "0" ] ; then
   echo "Your system is not seems to be systemD, trying systemV service start" 
   which service > /dev/null
   if [ "$?" -ne "0" ] ; then
        # Does not seems to exist systemV either #
        echo " Your system does not support systemV or systemD either. Can't continue." 
        exit -1;
    else 
        # Found systemV base system #
        echo "Found support for systemV base system." 
        setsid service cscored start > /dev/null
        if [ "$?" -ne "0" ] ; then
            echo "Corescanner service start...........................................[  FAILED  ]" 
            exit -1;
        else
            echo "Corescanner service start...........................................[  SUCCESS ]"
        fi
    fi
    sleep 10
  else 
    # your system is a systemD supportive system 
    echo "Found systemD base system" 
    systemctl stop cscored.service
    if [ "$?" -ne "0" ] ; then
        echo "Corescanner service stop............................................[  FAILED  ]" 
    else 
        echo "Corescanner service stop............................................[  SUCCESS ]" 
    fi
     # try to start the corescanner service                                     #
    systemctl start cscored.service
    if [ "$?" -ne "0" ]; then
        echo "Corescanner service start...........................................[  FAILED  ]"
    exit -1; 
    else 
        echo "Corescanner service start...........................................[  SUCCESS ] "
    fi
    sleep 10
    fi
    }

    2. Execute SMS and wait for execution completion. 
   

#Execute SMS and wait till execution is complete
   gnusms
   if [ "$?" -ne "0" ] ; then 
    echo "SMS Execution start.................................................[  FAILED  ]" 
  else 
    echo "SMS Execution Start.................................................[  SUCCESS ] "
  fi 
  counter=0
  while [ $counter -le 1 ]; do
    ps -e | grep gnusms > /dev/null
    if [ "$?" -ne "0" ]; then
        echo "SMS Execution finished..............................................[  SUCCESS ]" 
        counter=2
    fi
    sleep 5
done

    3. Upon SMS execution completion, stop the CoreScanner service. 
   

stop_coreScanner_driver () {
   #Stop CoreScanner driver
  # :NOTE: different systems does start/stop/status/restart corescanner deamon   #
  # in different way. Some are using systemD and some are using systemV.         #
 # First we have to check whether system is supporting systemV or systemD.      #
  echo "Stopping CoreScanner service." 

  which systemctl 2&> /dev/null
   if [ "$?" -ne "0" ] ; then
    echo "Your system is not seems to be systemD, trying systemV service start" 
    which service > /dev/null
    if [ "$?" -ne "0" ] ; then
        # Does not seems to exist systemV either #
        echo " Your system does not support systemV or systemD either. Can't continue." 
        exit -1;
    else 
        # Found systemV base system #
        echo "Found support for systemV base system." 
    setsid service cscored stop  > /dev/null
    if [ "$?" -ne "0" ] ; then
            echo "Corescanner service stop............................................[  FAILED  ]" 
    else 
            echo "Corescanner service stop............................................[  SUCCESS ]" 
    fi
    fi
    sleep 10

else 
    # your system is a systemD supportive system 
    echo "Found systemD base system" 

    systemctl stop cscored.service
    if [ "$?" -ne "0" ] ; then
        echo "Corescanner service stop............................................[  FAILED  ]" 
    else 
        echo "Corescanner service stop............................................[  SUCCESS ]" 
    fi
    sleep 10
  fi
  }

    4. Start the gedit application. 
   

#Open gedit application, Can replace with any application or script
   echo "Opening gedit application"
   gedit temp.txt