LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-25-2024, 05:08 AM   #1
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Rep: Reputation: Disabled
find & mv with xargs


Hi Folks;

Could you help me with find and xargs? This is what I'm stuck with:

Code:
#!/bin/sh
set -x
SRC='/media/sdmmc/mmcblk0p1/RECORD/'
EXPORT_FOLDER='/media/sdmmc/mmcblk0p1/RECORD/EXPORTS/'

mkdir -p "$EXPORT_FOLDER"

find "$SRC" -name "*.mkv" -mmin +1 -print0 | xargs -i {}  mv {} $EXPORT_FOLDER
for some reason this is the error message:

Code:
xargs: invalid option -- 'i'
BusyBox v1.22.1 (2014-07-03 15:30:22 CST) multi-call binary.

Usage: xargs [OPTIONS] [PROG ARGS]

Run PROG on every item given by stdin

        -p      Ask user whether to run each command
        -r      Don't run command if input is empty
        -0      Input is separated by NUL characters
        -t      Print the command on stderr before execution
        -e[STR] STR stops input processing
        -n N    Pass no more than N args to PROG
        -s N    Pass command line of no more than N bytes
        -x      Exit if size is exceeded
I was trying with this as well:
Code:
+ find /media/sdmmc/mmcblk0p1/RECORD/ -name *.mkv -mmin +1 -print0
mv: can't stat '/media/sdmmc/mmcblk0p1/RECORD/M-20240325_104804_0002/2024-03-25__11_08_15.mkv/{}': Path has non-directory component
mv: can't stat '/media/sdmmc/mmcblk0p1/RECORD/M-20240325_104804_0002/2024-03-25__11_08_15.mkv/EXPORTS': Path has non-directory component
mv: can't stat '/media/sdmmc/mmcblk0p1/RECORD/M-20240325_104804_0002/2024-03-25__11_08_15.mkv/2024-03-25__10_58_10.mkv': Path has non-directory component

Last edited by kzo81; 03-25-2024 at 05:16 AM.
 
Old 03-25-2024, 05:39 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
-print0 is \0 terminated and needs xargs -0

And obviously your xargs version doesn't know -i

Try
Code:
find "$SRC" -name "*.mkv" -mmin +1 -print0 | xargs -0 mv -t "$EXPORT_FOLDER"
Without xargs:
Code:
find "$SRC" -name "*.mkv" -mmin +1 -exec mv -t "$EXPORT_FOLDER" {} +
 
1 members found this post helpful.
Old 03-25-2024, 05:46 AM   #3
lvm_
Member
 
Registered: Jul 2020
Posts: 927

Rep: Reputation: 337Reputation: 337Reputation: 337Reputation: 337
Apparently you are trying to run this on busybox https://linux.die.net/man/1/busybox, a shell commonly found on various small devices - routers and such. It's lightweight, but its capabilities are very limited, its built-in xargs supports just want it printed and no more.
 
Old 03-25-2024, 06:22 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Amazing how a few messages help illuminate things ... :sheesh:
I had read this before they were editted in.
 
Old 03-25-2024, 07:29 AM   #5
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Hi, thanks for the suggestion without xargs, but
Code:
mv: invalid option -- 't'
The problem with find AND exec is that SYSTEMD doesnt like it. The script never starts with the service file that contains exec
 
Old 03-25-2024, 07:39 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
[QUOTE=kzo81;6491774]Hi, thanks for the suggestion without xargs, but
Code:
mv: invalid option -- 't'
Again, you use busybox which has limited capabilities. You need to use simplified commands.
probably you need to implement in more steps.


Quote:
Originally Posted by kzo81 View Post
The problem with find AND exec is that SYSTEMD doesnt like it. The script never starts with the service file that contains exec
that is nonsense. systemd does not care about your shell and commands you execute in it.
 
Old 03-25-2024, 08:19 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
So your mv doesn't support -t
You can try
Code:
find "$SRC" -name "*.mkv" -mmin +1 -exec mv {} "$EXPORT_FOLDER" +
Some find versions need the {} at the end, then try
Code:
find "$SRC" -name "*.mkv" -mmin +1 -exec sh -c 'mv -f "$@" '"$EXPORT_FOLDER" sh {} +
 
1 members found this post helpful.
Old 03-25-2024, 08:31 AM   #8
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Cool

Some find versions need the {} at the end, then try
Code:
find "$SRC" -name "*.mkv" -mmin +1 -exec sh -c 'mv -f "$@" '"$EXPORT_FOLDER" sh {} +
[/QUOTE]

Yes!!! this one works! Thanks!!!
 
Old 03-27-2024, 01:49 AM   #9
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Hi Folks,

Im still struggling with that file syncronisation issue.

I got a script that is run by systemD.
If I run the script manually as root, its ok.
However when I start that script with systemD that red process line never gets executed. The files never move into that EXPORT folder.

Here is the script:
Code:
#!/bin/sh

set -x

MAC=$(ip a | grep ether | head -1 | awk '{print $2}' | sed 's/:/-/g')
CONFIG="/usr/bin/syncroniser.cfg"
KEY="/usr/bin/dropbear_rsa_host_key"
SRC="/media/sdmmc/mmcblk0p1/RECORD/"
EXPORTS="/media/sdmmc/mmcblk0p1/RECORD/EXPORTS/"
DST="$MAC"
FREQ=60

while true
    do
        if test -f "$CONFIG"; then
            . "$CONFIG"
        fi
        
        mkdir -p "$EXPORTS"
        
        find "$SRC" -name "*.mkv" -mmin +1 -exec sh -c 'mv -f "$@" '"$EXPORTS" sh {} +

        rsync --remove-source-files --timeout=30 -avme "ssh -i $KEY -p $REMOTE_PORT" $EXPORTS $REMOTE_USER@$REMOTE_IP:$DST
                   
        sleep $FREQ
        
    done
This is the systemD status:
Code:
systemctl status syncroniser
● syncroniser.service - Remote Syncroniser
   Loaded: loaded (/etc/systemd/system/syncroniser.service; disabled)
   Active: active (running) since Wed 2024-03-27 07:41:41 CET; 9s ago
 Main PID: 5645 (sh)
   CGroup: /system.slice/syncroniser.service
           ├─ 5645 /bin/sh /usr/bin/syncroniser
           ├─11079 find /media/sdmmc/mmcblk0p1/RECORD/ -name *.mkv -mmin +1 -exec sh -c mv -f "$@" /media/sdmmc/mmcblk0p1/RECORD/EXPORTS/ sh {} +
           └─11218 n/a
# 
# 
# systemctl status syncroniser
● syncroniser.service - Remote Syncroniser
   Loaded: loaded (/etc/systemd/system/syncroniser.service; disabled)
   Active: active (running) since Wed 2024-03-27 07:41:41 CET; 20s ago
 Main PID: 5645 (sh)
   CGroup: /system.slice/syncroniser.service
           ├─ 5645 /bin/sh /usr/bin/syncroniser
           ├─17981 rsync --remove-source-files --timeout=30 -avme ssh -i /usr/bin/dropbear_rsa_host_key -p 2222 /media/sdmmc/mmcblk0p1/RECORD/EXPORTS/ encoder@1.2.3.4:encoder
           └─17982 ssh -i /usr/bin/dropbear_rsa_host_key -p 2222 -l encoder -4 1.2.3.4 rsync --server -vlmosdtpre.iLgfxCIiu --timeout=30 --remove-source-files . encoder
This is the unit file:
Code:
[Unit]
Description=Remote Syncroniser
After=network.target

[Service]
Restart=on-failure
User=root
Type=simple
ExecStart=/bin/sh /usr/bin/syncroniser

[Install]

Last edited by kzo81; 03-27-2024 at 01:51 AM.
 
Old 03-27-2024, 01:53 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
I think it is executed, there is a pid associated with it. Probably you need to check the logs to understand what's going on.
 
1 members found this post helpful.
Old 03-27-2024, 02:08 AM   #11
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
for some reason the filesystem became read only :-)))) I dont know whats happening :-)

Code:
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_32_58.mkv': Read-only file system
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_38_00.mkv': Read-only file system
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_43_03.mkv': Read-only file system
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_48_05.mkv': Read-only file system
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_53_07.mkv': Read-only file system
mv: can't rename '/media/sdmmc/mmcblk0p1/RECORD/M-20240326_235920_0002/2024-03-27__07_58_10.mkv': Read-only file system
 
Old 03-27-2024, 05:23 AM   #12
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
If you now manually run the script, do you get the read-only error message?
Is it a virtual machine? If yes, how is it on the host machine?
 
1 members found this post helpful.
Old 03-27-2024, 05:38 AM   #13
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
If you now manually run the script, do you get the read-only error message?
Is it a virtual machine? If yes, how is it on the host machine?
Yes, when I run in manually. I reformatted the SD card. It wasnt read only before
 
Old 03-27-2024, 05:44 AM   #14
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
This is the script now:
Code:
#!/bin/sh

set -x

MAC=$(ip a | grep ether | head -1 | awk '{print $2}' | sed 's/:/-/g')
CONFIG="/usr/bin/syncroniser.cfg"
KEY="/usr/bin/dropbear_rsa_host_key"
SRC="/media/sdmmc/mmcblk0p1/RECORD/"
EXPORTS="/media/sdmmc/mmcblk0p1/RECORD/EXPORTS/"
DST="$MAC"
FREQ=60

while true
    do
        if test -f "$CONFIG"; then
            . "$CONFIG"
        fi
        mkdir -p "$EXPORTS"       
        find $SRC -mmin +1 -type f -name *.mkv -exec mv "{}" $EXPORTS \;
        rsync --remove-source-files --timeout=30 -avme "ssh -i $KEY -p $REMOTE_PORT" $EXPORTS $REMOTE_USER@$REMOTE_IP:$DST
                   
        sleep $FREQ
        
    done
If I start it manually, it works like a charm. However if I start it with systemD, the "green find" line never happens, I suspect the red part at the end somehow have an impact on systemD
 
Old 03-27-2024, 06:21 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by kzo81 View Post
However if I start it with systemD, the "green find" line never happens, I suspect the red part at the end somehow have an impact on systemD
Forget that impact on systemd, do not hate it that much.
You can check if there is a pid for that find, and you will see it is running. \; just belongs to that find command at the end of the line.
The permission denied is a different issue, you need to find out why is it read only (no, it is not because of systemd).
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 07:26 PM
How to use xargs within xargs ? anindyameister Linux - Newbie 1 05-15-2013 05:01 AM
Several "find -exec" and "find | xargs" questions thanhvn Programming 4 12-02-2005 01:04 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
Gotta love those ٱٱٱٱٱٱٱ&# iLLuSionZ Linux - General 5 11-18-2003 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration