Skip to content

Tag: bash

top and grep output nothing when run from shell script

I am trying to create shell script that ssh into a remote server and run a script there and print the output in the local server but when I run the script in the local server it most of the time outputs nothing and rarely outputs data : and when I ssh in the local server to the remote server

Unable to get the absolute value of command output

So I wanted to make a simple script to keep checking the CPU temperature of my RasPi, which is stored in /sys/class/thermal/thermal_zone0/temp , and hence cat /sys/class/thermal/thermal_zone0/temp would give the temp, but like this : which essentially means 38.459 degree Celsius. I was unable to format the ou…

conditionally merge files by appending in bash

I have two files and would like to merge them – by appending to the last line. file1.txt content file2.txt content Desired outcome – file3.txt How do I go about this, please? Note, zero is in place for null in the Stack line. Answer Using awk: When file2.txt is read, store field2 in array a using …

Shell : create and assign variables inside for loop

i ve this shell script ; it’s a loop which set in the variable “a” each time result : My Purpose is how to change “a” by a dynamic variable name which be $item_MYPREFIX (concatination :$item + _MYPREFIX ) So that my code would be generic , something like this : and i would be abl…

How to find all symlinks to a file?

This is my hierarchy: l1 and l2 are symlinks to a.txt. I run this code to find all symlinks to a.txt in the /aaaaaaaa: And it obviously doesn’t work, cause I must compare realpath of file with path of a.txt. In what way I should do this? Answer If you have GNU/BSD find just use -samefile primary.