WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Bash script help  (Read 2112 times)

Offline MTCAT

  • Sr. Member
  • ****
  • Posts: 370
Bash script help
« on: April 21, 2023, 03:25:26 PM »
Hi everyone,

I would like to add the functionality/commands contained in test.sh into start_logger_TC.sh

test.sh, when run on its own, after running start_logger_TC.sh, works fine, but when I try to add the commands in test.sh to start_logger_TC.sh (at the end of start_logger_TC.sh, after all the "aterm ...." commands), the taskset commands don't get run properly.

Can I call a script file (test.sh) from within start_logger_TC.sh maybe? But I don't know why the test.sh commands wouldn't work in the start_logger_TC.sh file directly?

I'm trying to force mt_logger to run on one core (and stay there) and mt_adc to run on the other core, it seems to help stability as otherwise the two programs flip-flop between the two cores.

Thanks to your help I've got UDMA/100 going and with the taskset commands entered manually, I've ran the little system for more than 39 hrs with no adc timeout errors!

Just have to get the program to load some temperature readings from "digitemp" program, and maybe differentiate between GPS and Glonass satellites, and the system is ready to go!

Thanks,

David

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11576
Re: Bash script help
« Reply #1 on: April 21, 2023, 05:09:32 PM »
Hi MTCAT
The last line in  start_logger_TC.sh  is:
Code: [Select]
aterm -geometry 80x12+120+440 -title "MT Logger" -e sh -c "/home/tc/.local/bin/mt_logger "
... but when I try to add the commands in test.sh to start_logger_TC.sh (at the end of start_logger_TC.sh, after all the "aterm ...." commands), the taskset commands don't get run properly. ...
When you did that did you change the last line to:
Code: [Select]
aterm -geometry 80x12+120+440 -title "MT Logger" -e sh -c "/home/tc/.local/bin/mt_logger " &

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11576
Re: Bash script help
« Reply #2 on: April 21, 2023, 05:24:52 PM »
Hi MTCAT
You should probably also add a sleep command between the
last  aterm  command and the added  taskset  commands.

Offline MTCAT

  • Sr. Member
  • ****
  • Posts: 370
Re: Bash script help
« Reply #3 on: April 21, 2023, 05:26:31 PM »
Hi Rich,

Thanks for the help, no I did not change the last line of start_logger_TC.sh by adding the ampersand.

When I saw those ampersands in the start_logger_TC.sh script file I thought that it was for running the processes as background? Sorry, thinking about it, it wouldn't make sense to run the GUI as a background process since we wouldn't be able to interact with it?!

I need to add an ampersand to the last line in the original start_logger_TC.sh script in order to get the following taskset commands to run properly?

I was wondering about adding an extra sleep command there as well, thanks.

Thanks,

David

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11576
Re: Bash script help
« Reply #4 on: April 21, 2023, 10:50:49 PM »
Hi MTCAT
A command that provides a surface to draw on will display when launched
in the background. Open a terminal and try the following commands:
Code: [Select]
aterm -e top &
editor &
For the first command  aterm  provides the drawing surface.
For the second command  fltk  creates a window to draw on.

... I need to add an ampersand to the last line in the original start_logger_TC.sh script in order to get the following taskset commands to run properly? ...
Yes, you do. Consider the following example:
Code: [Select]
#!/bin/sh
Command1
Command2
Command2  can't run until  Command1  finishes. If you background
Command1  then  Command2  can run before  Command1  finishes.

If you don't add the ampersand, your taskset commands won't run
until the  mt_logger  program finishes running.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 708
Re: Bash script help
« Reply #5 on: April 22, 2023, 12:43:10 AM »
And one more thing, then running scripts in terminal in background and exit the terminal will also stops the script and the programs within.

So take this as an example, if you want to download some file and you span some new terminal window and then closes that window before the download command have finished.

You have to use the nohup command to disable this behavior like tthis.
Code: (bash) [Select]
nohup wget http://tinycorelinux.net/corebook.pdf &
This will also make a file with the stdout from script or program goes to file nohup.out

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11576
Re: Bash script help
« Reply #6 on: April 22, 2023, 10:30:40 AM »
Hi patrikg
And one more thing, then running scripts in terminal in background and exit the terminal will also stops the script and the programs within. ...
I think you are mistaken, see:
https://forum.tinycorelinux.net/index.php/topic,25999.msg166882.html#msg166882

I opened a terminal and entered:
Code: [Select]
busybox wget http://tinycorelinux.net/14.x/x86/release/CorePlus-14.0.iso &I then killed the terminal. The command just got re-parented to PID 1 and ran to completion.
Whether you kill the terminal by typing  exit , clicking the close button, or using the  kill
command made no difference.

The GNU version of wget did not even need to be backgrounded. I ran GNU wget like this:
Code: [Select]
wget http://tinycorelinux.net/14.x/x86/release/CorePlus-14.0.isoWhen I killed the terminal, the command still got re-parented to PID 1 and ran to completion.

Offline MTCAT

  • Sr. Member
  • ****
  • Posts: 370
Re: Bash script help
« Reply #7 on: April 22, 2023, 11:43:24 AM »
Hi Rich and patrikg,

Thanks a lot for the help, and the explanation, I added the ampersand to the previously last line of start_logger_TC.sh, then added a "sleep 10" followed by the taskset commands, it worked!

Now when executing the new start_logger_TC.sh we have mt_logger running on core 0 (~ 30 percent load of one core for the most part, ~ 40 percent load when the GUI is on the continuous screen though, more drawing to do), and mt_adc and gpsd running on core 1 (together taking up about 5 percent of core 1), the only other processes "floating around" across cores still (that we started up anyway) are tinierclock.sh and chrony, and they both seem to be less than 0.1 percent load,
so they seem to be just fine to move around to whichever core they want.

Thanks a lot, now on to getting some temperature readings into the program with digitemp!

David