Bash/Shell Scripting

Bash scripts can be used for various purposes such as executing specific commands, automating tasks, provisioning, etc; including the ability to consume apx- system tools.
This is useful when you want to automate things such as scanning and pairing nearby bt speakerphones, or authorize a particular network, perform a health check on the device, and more.

Bash script

To write a bash script you can create a new file using vi or nano.

$ nano

and enter the following contents

echo "my first bash script"

then change the script to be executable with the

$ chmod +x

Execute the script with ./

Now change the echo for a system tool command such as activating output 1

sudo apx-io set OUT1 true
$ ./

and if you do a sudo apx-io get out1 you'll see it returns "true"


Crontab is a tool that is used for running specific tasks on a regular interval.
It can be useful to run tasks periodically like resetting the wifi or activating an output.

To start using crontab you can use the crontab -e command

$ crontab -e

This will pull up an editor with a list of all the currently running crons.

The format for cron is as follow:

* * * * * /path/to/
│ │ │ │ └───> Day of Week (0-7) (0 & 7 are "Sunday")
│ │ │ └─────> Month of Year (1-12)
│ │ └───────> Day of Month (1-31)
│ └─────────> Hour (0-23)
└───────────> Minute (0-59)

For example, if we want to reset the wifi every 1hr, we can accomplish this with a bash script like:

sudo apx-wifi reset

and execute it with crontab:

*/10 * * * * /data/users/syrus4g/

Another example could be to start the hotspot on every system reboot, to accomplish this we could create a script like this

sudo apx-hotspot ssid Syrus4G
sudo apx-hotspot pass 123456

and execute it with crontab

@reboot /data/users/syrus4g/


lftp is a file transfer program that which allows us to manage files and upload them to remove servers via ftp and other protocols.

To get started we recommend creating subdirectories on a remote server using the device IMEI, followed by a subfolder for the type of media you want to upload:

# remote ftp server
├── 867698041101234/
│   ├── images/
│   │   ├── 1616442180-photo.jpeg
│   ├── videos/
│   │   ├── 1616442284-driver_cam_hard_braking.mp4
├── 867698041105678/
│   ├── images/
│   ├── videos/
│   ├── logs/

With the above in place you can upload media like this

# upload a photo
lftp -u username,password -p 4455 -e 'put /data/users/syrus4g/fatigue_sensor/1620415933-fatigue_remind.jpeg -o 867698041101234/images/1620415933-fatigue_remind.jpeg; bye'

# upload a video
lftp -u username,password -p 4455 -e 'put /data/users/syrus4g/video/1624969585_hard_braking_driver_cam.mp4 -o 867698041101234/videos/1624969585_hard_braking_driver_cam.mp4; bye'

lftp includes a command for mirroring the contents of a source folder with the remote server, make sure to add a -c option to continue the file transfer in case there's an interruption. Also you can use the --reverse flag to put all files from the Syrsu to the remote server, including subdirectories and their contents.

# reverse mirror images to destination server
lftp -u username,password -p 4455 -e 'mirror -c --reverse /data/users/syrus4g/fatigue_sensor/ 867698041101234/images/; bye'

# reverse mirror videos to destination server
lftp -u username,password -p 4455 -e 'mirror -c --reverse /data/users/syrus4g/video/ 867698041101234/videos/; bye'

once mirrored you can use the -n option to upload only newer files

# upload new images only
lftp -u username,password -p 4455 -e 'mirror -n --reverse /data/users/syrus4g/fatigue_sensor/ 867698041101234/images/; bye'

# upload new videos only
lftp -u username,password -p 4455 -e 'mirror -n --reverse /data/users/syrus4g/video/ 867698041101234/videos/; bye'

another useful option is to force ssl, which refuses to send the password in clear when the remote server does not support ssl

# force ssl connection to remote server
lftp -u username,password -p 4455 -e 'set ftp:ssl-force=true put /data/users/syrus4g/fatigue_sensor/1616442180-photo.jpeg 867698041101234/images/1616442180-photo.jpeg; bye'