Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
2
votes
6
answers
60
views
Check if multiple files exist on a remote server
I am writing a script that locates a special type of file on my system and i want to check if those files are also present on a remote machine. So to test a single file I use: ssh -T user@host [[ -f /path/to/data/1/2/3/data.type ]] && echo "File exists" || echo "File does not exist"; But since I hav...
I am writing a script that locates a special type of file on my system and i want to check if those files are also present on a remote machine.
So to test a single file I use:
ssh -T user@host [[ -f /path/to/data/1/2/3/data.type ]] && echo "File exists" || echo "File does not exist";
But since I have to check blocks of 10 to 15 files, that i would like to check in one go, since I do not want to open a new ssh-connection for every file.
My idea was to do something like:
results=$(ssh "user@host" '
for file in "${@}"; do
if [ -e "$file" ]; then
echo "$file: exists"
else
echo "$file: does not exist"
fi
done
' "${files_list[@]}")
Where the file list contains multiple file path. But this does not work, as a result, I would like to have the "echo" string for every file that was in the files_list.
Nunkuat
(123 rep)
Aug 6, 2025, 12:31 PM
• Last activity: Aug 6, 2025, 03:31 PM
38
votes
11
answers
40063
views
Check if script is started by cron, rather than invoked manually
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts. How can I know if the Bash script is started by cron ?
Is there any variable that cron sets when it runs a program ? If the script is run by cron, I would like to skip some parts; otherwise invoke those parts.
How can I know if the Bash script is started by cron ?
daisy
(55777 rep)
Aug 31, 2012, 09:07 AM
• Last activity: Aug 1, 2025, 12:17 PM
2
votes
1
answers
38
views
socat filter and replace character for modbus ascii
The goal is to get modbus ascii working with a Wallbox from ABL. So I placed a RS485 to TCP converter in the box, created a pseudo tty for my application and got the wrong frame. The answer starts with `>` and should start with `:`. So my approach is the following: ``` Terminal1: sudo socat -d -d -d...
The goal is to get modbus ascii working with a Wallbox from ABL.
So I placed a RS485 to TCP converter in the box, created a pseudo tty for my application and got the wrong frame.
The answer starts with
>
and should start with :
.
So my approach is the following:
Terminal1: sudo socat -d -d -d pty,link=/dev/ttyVA00,echo=0,perm=0777 pty,link=/dev/ttyVB00,echo=0,perm=0777
Terminal2: sudo socat -d -d -d pty,link=/dev/ttyV0,perm=0777 tcp:10.10.49.249:502
Terminal3: cat /dev/ttyVB00 > /dev/ttyV0
Terminal4: cat /:/g' > /dev/ttyVB00
Terminal5: ./modpoll -m ascii /dev/ttyVA00 -b 38400 -d 8 -p even -t4 -c 2 -0
And this works!
Could you give advice on how to simplify the socat solution and how to get it to autostart?
martin
(21 rep)
Jul 31, 2025, 10:49 AM
• Last activity: Aug 1, 2025, 08:57 AM
0
votes
1
answers
2602
views
Problem redirecting output to log file and console in bash script
I have a shell script which sucessfully redirects all output to a log file and stdout (console) at the same time. However, when it exits it seems to wait for some user input from the keyboard (experimentally, any key seems to work)... So, I run the script, see the output, it exits and I have to hit...
I have a shell script which sucessfully redirects all output to a log file and stdout (console) at the same time. However, when it exits it seems to wait for some user input from the keyboard (experimentally, any key seems to work)... So, I run the script, see the output, it exits and I have to hit e.g. the spacebar before the terminal prompt re-appears. Typing
echo $?
then gives the correct exit code.
The basics of the script are:
#!/bin/bash
LOG="./test.log"
rm -f $LOG
exec > >(tee $LOG) 2>&1
if [[ "$1" = "T" ]]; then
echo "twas true..."
exit 0
else
echo "twas false..."
exit 100
fi
Any help appreciated... not only do I not want to hit the spacebar but I would like to understand what is going on?
***Amendment***: it appears that I have to hit **enter** to get the terminal prompt back. From my limited experience using the *ps* command it would seem that my script has terminated and the *bash* shell is in the interruptible sleep state **S**. It would appear that maybe the terminal prompt output has been consumed or incorrectly redirected? I cannot see why...
Koorb Notsyor
(15 rep)
Sep 12, 2020, 04:56 PM
• Last activity: Jul 31, 2025, 04:03 PM
1
votes
1
answers
3177
views
How to automatically detect and write to usb with variable spaces in its name
I am doing the second BASH exercise from [TLDP Bash-Scripting Guide][1], and I have most of it figured out up until the part when it comes time to copy the compressed files to an inserted USB. > Home Directory Listing > > Perform a recursive directory listing on the user's home directory and save th...
I am doing the second BASH exercise from TLDP Bash-Scripting Guide , and I have most of it figured out up until the part when it comes time to copy the compressed files to an inserted USB.
> Home Directory Listing
>
> Perform a recursive directory listing on the user's home directory and save the information to a file. Compress the file, have the script
> prompt the user to insert a USB flash drive, then press ENTER.
> Finally, save the file to the flash drive after making certain the
> flash drive has properly mounted by parsing the output of df. Note
> that the flash drive must be unmounted before it is removed.
As I progress with the script it is becoming less ..elegant, and was wondering if there was a better way to do this. I know creating files is likely not the most efficient way to do the comparisons, but have not got the shell expansions figured yet, and intend to change those once I get it working.
The problem specifically is, to ensure that the usb is mounted and that I am writing to the USB and nowhere else. I am comparing the last line of
df
after the USB is plugged in with the last line of df
from the diff
between df
before USB is plugged in and df
after USB is plugged in, and looping until they match. Unfortunately, the diff
result starts with a >, but I intend to use sed to get rid of that. The real problem is the path to where my usb is mounted is:
> /media/flerb/"Title of USB with spaces"
To make this portable for USBs that may have different names is my best bet from here to do something with awk and field separators? And as a follow-up, I know this is pretty inelegant, and wonder if there is a cleaner way to go about this...especially because this is the second exercise and still in EASY.
The output from the df tails is:
/dev/sdb1 15611904 8120352 7491552 53% /media/flerb/CENTOS 7 X8
> /dev/sdb1 15611904 8120352 7491552 53% /media/flerb/CENTOS 7 X8
The script so far
1 #!/bin/bash
2
3 if [ "$UID" -eq 0 ] ; then
4 echo "Don't run this as root"
5 exit 1
6 fi
7
8 #Create a backup file with the date as title in a backup directory
9 BACKUP_DIR="$HOME/backup"
10 DATE_OF_COPY=$(date --rfc-3339=date)
11 BACKUP_FILE="$BACKUP_DIR/$DATE_OF_COPY"
12
13 [ -d "$BACKUP_DIR" ] || mkdir -m 700 "$BACKUP_DIR"
14
15 #find all files recursively in $HOME directory
16 find -P $HOME >> "$BACKUP_FILE"
17
18 #use lzma to compress
19 xz -zk --format=auto --check=sha256 --threads=0 "$BACKUP_FILE"
20
21 #making files to use in operations
22 BEFORE="$BACKUP_DIR"/before_usb.txt
23 AFTER="$BACKUP_DIR"/after_usb.txt
24 DIFFERENCE="$BACKUP_DIR"/difference.txt
25
26 df > "$BEFORE"
27 read -p 'Enter USB and press any button' ok
28 sleep 2
29 df > "$AFTER"
30 diff "$BEFORE" "$AFTER" > "$DIFFERENCE"
31 sleep 2
32 echo
33
34 TAIL_AFTER=$(tail -n 1 "$AFTER")
35 TAIL_DIFF=$(tail -n 1 "$DIFFERENCE")
36
37 until [ "$TAIL_AFTER" == "$TAIL_DIFF" ] ;
38 do
39 echo "Not yet"
40 df > "$AFTER"
41 TAIL_AFTER=$(tail -n 1 "$AFTER")
42 diff "$BEFORE" "$AFTER" > "$DIFFERENCE"
43 TAIL_DIFF=$(tail -n 1 "$DIFFERENCE")
44 echo "$TAIL_AFTER"
45 echo "$TAIL_DIFF"
46 sleep 1
47
48 done
49 exit $?
flerb
(983 rep)
Jul 12, 2017, 05:28 PM
• Last activity: Jul 30, 2025, 05:07 AM
1
votes
3
answers
2438
views
Searching /usr/dict/words to find words with certain properties
I would like to write a script to search through /usr/dict/words to find all words that meet some criteria I specify. For example, finding all palindromic words (like "racecar", "madam", etc.) or finding all words where the first and second halves reversed also form a word (like "german" and "manger...
I would like to write a script to search through /usr/dict/words to find all words that meet some criteria I specify. For example, finding all palindromic words (like "racecar", "madam", etc.) or finding all words where the first and second halves reversed also form a word (like "german" and "manger"). The framework of the script would be a simple loop to read each word in the dictionary, and I could change the criteria depending on what I want to look for by substituting an expression or something similar.
I figure I would need to involve regular expressions somehow (or otherwise find a way to look at individual characters in each word). I would also need a way to compare the characters in my current word to the other words in the dictionary (such as with my second example above).
What would be the best tool(s) to use for this task?
user161121
Mar 14, 2016, 11:31 PM
• Last activity: Jul 23, 2025, 10:05 AM
33
votes
6
answers
170050
views
Linux Bash Shell Script Error: cannot execute: required file not found
I have two similar scripts with different names. One works fine but other throws error. Can anyone please tell me what is the issue? This is my test.sh scripts which works fine ``` [nnice@myhost Scripts]$ cat test.sh #!/bin/bash function fun { echo "`hostname`" } fun [nnice@myhost Scripts]$ ./test.s...
I have two similar scripts with different names. One works fine but other throws error.
Can anyone please tell me what is the issue?
This is my test.sh scripts which works fine
[nnice@myhost Scripts]$ cat test.sh
#!/bin/bash
function fun {
echo "hostname
"
}
fun
[nnice@myhost Scripts]$ ./test.sh
myhost.fedora
Here is my another script demo.sh but it throws error
[nnice@myhost Scripts]$ cat demo.sh
#!/bin/bash
function fun {
echo "hostname
"
}
fun
[nnice@myhost Scripts]$ ./demo.sh
bash: ./demo.sh: cannot execute: required file not found
Both scripts having the same permissions
[nnice@myhost Scripts]$ ll test.sh
-rwxr-xr-x. 1 nnice nnice 65 Oct 21 10:47 test.sh
[nnice@myhost Scripts]$ ll demo.sh
-rwxr-xr-x. 1 nnice nnice 58 Oct 21 10:46 demo.sh
Nitin Kumar
(465 rep)
Oct 21, 2022, 05:41 AM
• Last activity: Jul 18, 2025, 03:01 PM
1
votes
1
answers
78
views
Process some Folders and format the output
In Linux there are some Folders. I want to process each of this Folders with the program `myprogramm`. I get a list with `ls -1` or much better, sure only Folders with: `find . -maxdepth 1 -type d -printf '%f\n' | tr -d '.' | sed '/^[[:space:]]*$/d'` I Can pipe this to xargs. `xargs -I {} -n1 -P1 $(...
In Linux there are some Folders.
I want to process each of this Folders with the program
myprogramm
.
I get a list with ls -1
or much better, sure only Folders with:
find . -maxdepth 1 -type d -printf '%f\n' | tr -d '.' | sed '/^[[:space:]]*$/d'
I Can pipe this to xargs.
xargs -I {} -n1 -P1 $(cat $TEMPDIR)/myprogramm -switch1 -switch2 -someoptions {}/ -o {}.info
In one line :
find . -maxdepth 1 -type d -printf '%f\n' | tr -d '.' | sed '/^[[:space:]]*$/d' | xargs -I {} -n1 -P1 $(cat $TEMPDIR/pwd)/myprogramm -switch1 -switch2 -someoptions {}/ -o {}.info
That works so far.
But i am looking for a way to bring a little bit info into it.
Everytime if myprogramm
ends, it would be nice to have an output like: Folder 1 of 22 finished
Count how many Folders exist can i do with:
find . -maxdepth 1 -type d -printf '%f\n' | tr -d '.' | sed '/^[[:space:]]*$/d' | wc -l
But how to bring this into the line they process each Folders? And how to count after every one is finished one up?
Next thing, how to bring a random sleep value after every finished myprogramm
run and count them down before to work at the next Folder?
A random sleep can do with sleep $(shuf -i 30-60 -n 1)
.
But how to bring this into, and how to show and count them down?
Banana
(189 rep)
Jul 13, 2025, 02:26 AM
• Last activity: Jul 13, 2025, 04:47 PM
2
votes
4
answers
4092
views
Shell script to check existence of multiple strings in a file
I have 3 strings A='apples' B='bananas' C='carrots' I want to see if all of these exist in the `fruit.txt` file. If I'm missing `A` then add `A`, `B` then add `B`, and so on. This is what I have now if grep -qF "$A | $B | $C" fruit.txt; then echo 'exist' else echo 'does not exist' echo $A $B $C >> f...
I have 3 strings
A='apples'
B='bananas'
C='carrots'
I want to see if all of these exist in the
fruit.txt
file.
If I'm missing A
then add A
, B
then add B
, and so on.
This is what I have now
if grep -qF "$A | $B | $C" fruit.txt;
then echo 'exist'
else
echo 'does not exist'
echo $A $B $C >> fruit.txt
fi
nguye313
(21 rep)
Jun 23, 2020, 09:54 PM
• Last activity: Jul 8, 2025, 11:04 PM
0
votes
1
answers
3148
views
Check if user exists in /etc/passwd, if they exist, create new one with prefix
Kinda stuck here, did not find any solution. Check if user exists in `/etc/passwd`, if they exist, create new one with prefix `new_the_existed_one` ``` #!/bin/bash myuser="/home/yakyak/Desktop/Exercises/newusers.txt" sed '/^[ \t]*$/d' $myuser | while read -r line do name="$line" # adduser --disabled...
Kinda stuck here, did not find any solution.
Check if user exists in
/etc/passwd
, if they exist, create new one with prefix new_the_existed_one
#!/bin/bash
myuser="/home/yakyak/Desktop/Exercises/newusers.txt"
sed '/^[ \t]*$/d' $myuser | while read -r line
do
name="$line"
# adduser --disabled-login --gecos "" $name
# check if user exist
isthere=$(cut -d: -f1 /etc/passwd | grep "$name")
# if user was added then make insert record into log file
if [[ "$isthere" == "$name" ]]
then
echo "User already exist, creating new user.."
adduser --disabled-login
# adduser --disabled-login --gecos " " $name
fi
done
YakyAK
(23 rep)
Jan 27, 2022, 01:13 AM
• Last activity: Jul 3, 2025, 03:27 PM
0
votes
3
answers
150
views
What are the secure ways to use credentials in bash scripts?
I have a third-party service. Its API and credentials let me scrape service data on my local Linux machine. I want to use this API inside a bash script and launch it via `cron`, but I don't want to store credentials in plain text in the script. What are the best practices for authentication?
I have a third-party service. Its API and credentials let me scrape service data on my local Linux machine. I want to use this API inside a bash script and launch it via
cron
, but I don't want to store credentials in plain text in the script.
What are the best practices for authentication?
Aleksey
(57 rep)
Jul 2, 2025, 07:39 AM
• Last activity: Jul 2, 2025, 06:46 PM
2
votes
1
answers
3480
views
Bash script to re-run program when it finishes or crashes
This is what I have so far: until python MyApp.py; do echo "App crashed... restarting..." >&2 sleep 1 done This will re-run the program when it crashes, but not when the program finishes on its own.
This is what I have so far:
until python MyApp.py; do
echo "App crashed... restarting..." >&2
sleep 1
done
This will re-run the program when it crashes, but not when the program finishes on its own.
Vic
(193 rep)
Jul 26, 2016, 01:53 PM
• Last activity: Jun 29, 2025, 06:16 AM
0
votes
1
answers
97
views
How to match exact string?
I tried this grep -rn "application_config_project" . I got many application_config_project_name = f"{app_acronym}-application-config" github_application_config_repo = application_github_organization.get_repository(application_config_project_name) f"Initializing Application Config Project {applicatio...
I tried this
grep -rn "application_config_project" .
I got many
application_config_project_name = f"{app_acronym}-application-config"
github_application_config_repo = application_github_organization.get_repository(application_config_project_name)
f"Initializing Application Config Project {application_config_project_name}"
how to restrict my search just to
application_config_project
?
MJoao
(47 rep)
Jun 27, 2025, 08:14 AM
• Last activity: Jun 28, 2025, 01:48 AM
0
votes
5
answers
156
views
Rename a set of files according to a specific scheme, with rename back option
In Linux in a directory there are files, `ls -1` shows me this output : file1.1-rvr file1.2-rvr file1.3 file1.4-rvr file1.5 file1.6-rvr file2.1 file2.2 file3.1 file3.10 file3.2-rvr file3.3-rvr file3.4 file3.5 file3.6 file3.7 file3.8 file3.9 file4.1 file4.2 file5.1-rvr file5.2 file6.1 file6.2 file6.3...
In Linux in a directory there are files,
ls -1
shows me this output :
file1.1-rvr
file1.2-rvr
file1.3
file1.4-rvr
file1.5
file1.6-rvr
file2.1
file2.2
file3.1
file3.10
file3.2-rvr
file3.3-rvr
file3.4
file3.5
file3.6
file3.7
file3.8
file3.9
file4.1
file4.2
file5.1-rvr
file5.2
file6.1
file6.2
file6.3
file6.4
file7.1
file7.2-rvr
file7.3
file7.4
file7.5
file7.6
file8.1
file8.2
file8.3-rvr
file8.4
In this directory are only files with file names that begin with file
.
There are no other files in there.
file1.*
is a package
file2.*
is a (different) package too
and so on.
Each package should have its own random name.
For the randomness i will use.
cat /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c $(shuf -i 8-32 -n 1)
In each package, the .
should be renamed to .part.rar
.
Files with -rvr
should renamed too.
For example:
file3.1
file3.10
file3.2-rvr
file3.3-rvr
file3.4
file3.5
file3.6
file3.7
file3.8
file3.9
should be renamed for testing and experimenting to:
rfiqDLhZF5XxRcJXkqR1LrwniDi.part01.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part10.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part02.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part03.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part04.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part05.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part06.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part07.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part08.rar
rfiqDLhZF5XxRcJXkqR1LrwniDi.part09.rar
(If there are a *.10, 1 must be rename to 01.)
But there must be a way to note (in a file ../renamed
) the renaming in order to rename them back to the original filenames later.
For renaming all files in random names, i can use this, but i dont know how to work with the .part.rar renaming.
for file in file*; do
while true; do
RANDOM_NAME=$(cat /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c $(shuf -i 8-32 -n 1));
if [ ! -f ${RANDOM_NAME} ]; then
echo "${file}" "${RANDOM_NAME}" >> ../renamed
mv "${file}" "${RANDOM_NAME}";
break;
fi
done
done
For renaming back, i can use this one liner :
`while read old new rest ; do mv $new $old ; done .rar and back again.
EDIT
I am looking for a way to do that in Bash.
Here is a complete list with the current file names and the new filename scheme:
current name new name
------------ --------------------------------------
file1.1-rvr --> cL5617iQyc8kT5GwNoi.part1.rar
file1.2-rvr --> cL5617iQyc8kT5GwNoi.part2.rar
file1.3 --> cL5617iQyc8kT5GwNoi.part3.rar
file1.4-rvr --> cL5617iQyc8kT5GwNoi.part4.rar
file1.5 --> cL5617iQyc8kT5GwNoi.part5.rar
file1.6-rvr --> cL5617iQyc8kT5GwNoi.part6.rar
file2.1 --> QuMPmQjppRSuG3QL9xy5.part1.rar
file2.2 --> QuMPmQjppRSuG3QL9xy5.part2.rar
file3.1 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part01.rar
file3.10 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part02.rar
file3.2-rvr --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part03.rar
file3.3-rvr --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part04.rar
file3.4 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part05.rar
file3.5 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part06.rar
file3.6 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part07.rar
file3.7 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part08.rar
file3.8 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part09.rar
file3.9 --> rfiqDLhZF5XxRcJXkqR1LrwniDi.part10.rar
file4.1 --> cLYtCmUW.part1.rar
file4.2 --> cLYtCmUW.part2.rar
file5.1-rvr --> uXjOgcreTUCC7aHKkXeWPL1SiVdX.part1.rar
file5.2 --> uXjOgcreTUCC7aHKkXeWPL1SiVdX.part2.rar
file6.1 --> 9CcsiBYcuASF0ECoS.part1.rar
file6.2 --> 9CcsiBYcuASF0ECoS.part2.rar
file6.3 --> 9CcsiBYcuASF0ECoS.part3.rar
file6.4 --> 9CcsiBYcuASF0ECoS.part4.rar
file7.1 --> SXKymGb5Z9ImrQ0K51IUAA.part1.rar
file7.2-rvr --> SXKymGb5Z9ImrQ0K51IUAA.part2.rar
file7.3 --> SXKymGb5Z9ImrQ0K51IUAA.part3.rar
file7.4 --> SXKymGb5Z9ImrQ0K51IUAA.part4.rar
file7.5 --> SXKymGb5Z9ImrQ0K51IUAA.part5.rar
file7.6 --> SXKymGb5Z9ImrQ0K51IUAA.part6.rar
file8.1 --> 5poLf4stv6.part1.rar
file8.2 --> 5poLf4stv6.part2.rar
file8.3-rvr --> 5poLf4stv6.part3.rar
file8.4 --> 5poLf4stv6.part4.rar
But all before .partX(X).rar
should be random and generate with :
cat /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c $(shuf -i 8-32 -n 1)
Banana
(189 rep)
Jun 20, 2025, 01:32 AM
• Last activity: Jun 24, 2025, 11:13 AM
0
votes
1
answers
2322
views
permission needed for Python to access USB drive?
I got this Python script that reads media files from USB stick. It used to run fine, today it keeps giving me `OS Error: [Errno 13] Permission denied: media/myName/usbName` when the script runs the command `os.listdir()`. `os.listdir()` simply checks what folders and files are in the main folder. It...
I got this Python script that reads media files from USB stick. It used to run fine, today it keeps giving me
OS Error: [Errno 13] Permission denied: media/myName/usbName
when the script runs the command os.listdir()
.
os.listdir()
simply checks what folders and files are in the main folder. It doesn't write anything, so why is there a permission error? I can use the USB stick just fine, open, add and delete files in it myself. I'm not very experienced with Linux, what might be the issue? Some kind of permission, etc. setting for the script file or the usb drive that somehow magically changed without me doing anything?
Using Lubuntu 14.04.
Leo Ervin
(121 rep)
Sep 25, 2015, 10:15 PM
• Last activity: Jun 23, 2025, 10:05 PM
177
votes
5
answers
307845
views
How can I execute local script on remote machine and include arguments?
I have written a script that runs fine when executed locally: ./sysMole -time Aug 18 18 The arguments **"-time"**, **"Aug"**, **"18"**, and **"18"** are successfully passed on to the script. Now, this script is designed to be executed on a remote machine but, from a local directory on the local mach...
I have written a script that runs fine when executed locally:
./sysMole -time Aug 18 18
The arguments **"-time"**, **"Aug"**, **"18"**, and **"18"** are successfully passed on to the script.
Now, this script is designed to be executed on a remote machine but, from a local directory on the local machine. Example:
ssh root@remoteServer "bash -s" < /var/www/html/ops1/sysMole
That also works fine. But the problem arises when I try to include those aforementioned arguments **(-time Aug 18 18)**, for example:
ssh root@remoteServer "bash -s" < /var/www/html/ops1/sysMole -time Aug 18 18
After running that script I get the following error:
bash: cannot set terminal process group (-1): Invalid argument
bash: no job control in this shell
Please tell me what I'm doing wrong, this greatly frustrating.
AllenD
(2507 rep)
Aug 20, 2013, 01:52 AM
• Last activity: Jun 22, 2025, 07:27 PM
0
votes
0
answers
37
views
Finding and removing duplicate files: Integrating a unix script with an application that opens a file for viewing?
Does anyone know of an open source application or perhaps how to integrate an existing find dupes script with some OS tool (emacs, vim, Finder.app, mc, etc...) to open a file before marking that file for deletion? And perhaps know of open source Unix based console based tools that manage and delete...
Does anyone know of an open source application or perhaps how to integrate an existing find dupes script with some OS tool (emacs, vim, Finder.app, mc, etc...) to open a file before marking that file for deletion? And perhaps know of open source Unix based console based tools that manage and delete duplicate files? I'm using MacOS.
I'm asking here because it's Unix related and I'm hoping to leverage some dupes scripts if necessary.
I created the following script to find duplicate files and create output with
#rm duplicate_filen
in groups such that a line can be commented out and the script invoked to delete duplicates. I'm wondering if such scripts could be used with other applications. Hoping to ask here before reinventing this.
#!/usr/bin/env ksh
FINDOUT=$(mktemp)
( find "${@}" -type f -print0 | xargs -0 shasum ) > $FINDOUT
HASHES=$(find "${@}" -type f -print0 | xargs -0 shasum | awk '{ print $1; }' | sort | uniq -d)
DUPELIST=$(mktemp)
DUPES=$(mktemp)
for h in $HASHES; do
if grep "^$h " $FINDOUT >> $DUPES; then
echo "" >> $DUPELIST
cat $DUPES >> $DUPELIST
fi
rm $DUPES
done
RMSCRIPT=$(mktemp)
cat $DUPELIST | cut -d " " -f 2- > $RMSCRIPT
echo "#!/usr/bin/env ksh"
echo "# Duplicate files, remove comments and invoke script"
while read -r l; do
if [ "$l" != "" ]; then
echo "#rm \"$l\""
else
echo $l
fi
done < $RMSCRIPT
rm $FINDOUT $RMSCRIPT $DUPELIST
atod
(155 rep)
Jun 21, 2025, 03:54 AM
• Last activity: Jun 21, 2025, 04:49 AM
0
votes
2
answers
62
views
In a text file, finding and deleting lines including (e.g.) "#', or a word?
I am using Ubuntu Linux and Mageia Linux... I wish to do the following: in a text file (sample.txt), find and delete every line comprising the symbol '#' (or '?') or a specific word (e.g. 'mobile') Any idea how to start ? Thanks a lot Vincent
I am using Ubuntu Linux and Mageia Linux...
I wish to do the following:
in a text file (sample.txt), find and delete every line comprising the symbol '#' (or '?') or a specific word (e.g. 'mobile')
Any idea how to start ?
Thanks a lot
Vincent
Vinz M
(11 rep)
Jun 16, 2025, 12:16 PM
• Last activity: Jun 18, 2025, 05:54 AM
1
votes
2
answers
27311
views
Systemd service fails with exit-code 2: Start request repeated too quickly
I created a ClamAV on-access scanning systemd service, to be permanent so that I can enable, start and then leave it, without having to touch it again. I can manually start the service, and it works fine. But it keeps failing to start automatically after login as expected. In both cases, there are n...
I created a ClamAV on-access scanning systemd service, to be permanent so that I can enable, start and then leave it, without having to touch it again.
I can manually start the service, and it works fine. But it keeps failing to start automatically after login as expected. In both cases, there are no active network connections.
I believe the following journal output (found in last ouput section of the post) could be a clue:
rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
But I still don't why I'm able to manually start the service, but not have it start automatically.
# System info
$ uname -a
Linux debian 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux
# rc-local.service file
$ sudo cat /etc/systemd/system/rc-local.service
[Unit]
Description=ClamAV On-Access Scanner
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
User=root
Require=network.target
RemainAfterExit=yes
ExecStart=/etc/rc.local start
TimeoutSec=200
Restart=on-failure
StartLimitInterval=10
[Install]
WantedBy=multi-user.target
# rc.local script
$ sudo cat /etc/rc.local
#!/bin/sh -e
/usr/bin/clamonacc --log=/var/log/clamav/clamonacc.log
exit 0
# Status after logging in
● rc-local.service - ClamAV On-Access Scanner
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: failed (Result: exit-code) since Wed 2020-10-21 08:06:33 BST; 12min ago
Process: 1483 ExecStart=/etc/rc.local start (code=exited, status=2)
Oct 21 08:06:33 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:33 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 5.
Oct 21 08:06:33 debian systemd: Stopped ClamAV On-Access Scanner.
Oct 21 08:06:33 debian systemd: rc-local.service: Start request repeated too quickly.
Oct 21 08:06:33 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:33 debian systemd: Failed to start ClamAV On-Access Scanner.
# Status after manually starting service
● rc-local.service - ClamAV On-Access Scanner
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (running) since Wed 2020-10-21 08:23:04 BST; 52s ago
Process: 7171 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
Main PID: 7173 (clamonacc)
Tasks: 8 (limit: 4915)
Memory: 2.6M
CGroup: /system.slice/rc-local.service
└─7173 /usr/bin/clamonacc --log=/var/log/clamav/clamonacc.log
Oct 21 08:23:04 debian systemd: Starting ClamAV On-Access Scanner...
Oct 21 08:23:04 debian systemd: Started ClamAV On-Access Scanner.
# Journal
$ sudo journalctl | grep rc-local
Oct 21 08:06:22 debian systemd: /etc/systemd/system/rc-local.service:7: Unknown lvalue 'Require' in section 'Service', ignoring
Oct 21 08:06:31 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 08:06:31 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:31 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:31 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 1.
Oct 21 08:06:31 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 08:06:31 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:32 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:32 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 2.
Oct 21 08:06:32 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 08:06:32 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:32 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:32 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 3.
Oct 21 08:06:32 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 08:06:32 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:32 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:32 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 4.
Oct 21 08:06:32 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 08:06:32 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 08:06:33 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 08:06:33 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 5.
Oct 21 08:06:33 debian systemd: rc-local.service: Start request repeated too quickly.
Oct 21 08:06:33 debian systemd: rc-local.service: Failed with result 'exit-code'.
$ sudo journalctl | grep rc.local
Oct 21 13:47:57 debian rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
Oct 21 13:47:57 debian rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
Oct 21 13:47:57 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 13:47:57 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:47:57 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 13:47:57 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 1.
Oct 21 13:47:57 debian rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
Oct 21 13:47:57 debian rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
Oct 21 13:47:57 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 13:47:57 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:47:58 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 13:47:58 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 2.
Oct 21 13:47:58 debian rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
Oct 21 13:47:58 debian rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
Oct 21 13:47:58 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 13:47:58 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:47:58 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 13:47:58 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 3.
Oct 21 13:47:58 debian rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
Oct 21 13:47:58 debian rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
Oct 21 13:47:58 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 13:47:58 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:47:58 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 13:47:58 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 4.
Oct 21 13:47:58 debian rc.local: ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
Oct 21 13:47:58 debian rc.local: ERROR: Clamonacc: daemon is local, but a connection could not be established
Oct 21 13:47:58 debian systemd: rc-local.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Oct 21 13:47:58 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:47:59 debian systemd: rc-local.service: Service RestartSec=100ms expired, scheduling restart.
Oct 21 13:47:59 debian systemd: rc-local.service: Scheduled restart job, restart counter is at 5.
Oct 21 13:47:59 debian systemd: rc-local.service: Start request repeated too quickly.
Oct 21 13:47:59 debian systemd: rc-local.service: Failed with result 'exit-code'.
Oct 21 13:48:14 debian sudo: squire : TTY=pts/0 ; PWD=/home/squire ; USER=root ; COMMAND=/usr/sbin/service rc-local status
Oct 21 13:54:30 debian sudo: squire : TTY=pts/1 ; PWD=/home/squire ; USER=root ; COMMAND=/usr/sbin/service rc-local status
5am
(333 rep)
Oct 21, 2020, 07:37 AM
• Last activity: Jun 17, 2025, 01:06 PM
1
votes
1
answers
2167
views
Problem with inotify-wait as daemon
I have been running inotify-wait on my ftp server in byobu to monitor a folder, move data, and send email notifications for a few months without problems. Since I started this I have added 3 more folders that I monitor and I would like to start running inotify-wait as a daemon instead of in byobu se...
I have been running inotify-wait on my ftp server in byobu to monitor a folder, move data, and send email notifications for a few months without problems. Since I started this I have added 3 more folders that I monitor and I would like to start running inotify-wait as a daemon instead of in byobu sessions. I modified my script to be easier to only require a single variable to be changed and to run as a daemon. Unfortunately it now does nothing. I was hoping someone with some experience could take a look and tell me where Ive gone wrong.
#!/usr/bin/env bash
user=testuser
dir=/ftp/"$user"/upload/
log=/ftp/"$user"/log/"$user.log"
archive=/ftp/"$user"/archive/
target=/ftp/FTPDATA/"$user"/
inotifywait -q\
-d "$dir" \
-o "$log" \
-e close_write --format %f . | while IFS= read -r file; do
cp -p "$file" "$target"
/scripts/"$user-notify.sh"
mv "$file" "$archive""$(date +%F-%T)"
done
rfinterference
(11 rep)
Jul 21, 2015, 03:14 PM
• Last activity: Jun 15, 2025, 02:03 PM
Showing page 1 of 20 total questions