D
D
Drno2022-03-14 15:18:56
bash
Drno, 2022-03-14 15:18:56

How to add a script?

Good day.
There is a sh script - pulls out an mp4 file after recording and copies the line that does this to another folder
find "$DIR" -name "*.mp4" -print0 | xargs -i'{}' -0 cp '{}' /config/rec/

I would like it to pre-create a folder by file name (naturally without the mp4 extension)
So that the final folder is not /config/rec/ but /config/rec/ "namefile"/

And then this folder name should be put into the line rclone
rclone copy /config/rec/"namefile" cloud: --max-age 12h --create-empty-src-dirs -P --transfers=1 -- checkers=1;

If anyone is not lazy - tell me_)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AVKor, 2022-03-14
@AVKor

#!/usr/bin/env bash

while IFS= read -r -d '' file; do
  file_name=$(basename "$file" | cut -d "." -f 1)
  target_dir="/config/rec/$file_name"
  mkdir -p "$target_dir"
  cp "$file" "$target_dir"
  rclone copy "$target_dir" cloud: --max-age 12h --create-empty-src-dirs -P --transfers=1 --checkers=1;
done < <(find "$DIR" -name "*.mp4" -print0)

rcloneI don't use it, so check this part for yourself.

H
hint000, 2022-03-14
@hint000

you can do a one-liner:

find "$DIR" -name "*.mp4" -printf "%P\n" | xargs -i{} basename {} .mp4 | pee 'xargs -i{} mkdir -p /config/rec/{}' 'xargs -i{} cp {}.mp4 /config/rec/{}/' 'xargs -i{} rclone copy /config/rec/{}/{}.mp4 cloud: --max-age 12h --create-empty-src-dirs -P --transfers=1 --checkers=1;'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question