Unable to do rsync with find command - rsync

I'm trying to do rsync from destination server to remote server with sshpass and find command I'm using the below command but it's failed,
command:
sshpass -p password#1 find . -type f -name "*"`date -d '1 day ago' '+%Y-%m-%d'`"*" | rsync -avH root#10.31.0.0:/var/lib/edb/as12/data/log .
I Tried the below command but failed to do rsync from destination server to remote server facing problem to use find command with rsync. I want to do search the particular pattern files and then rsync those files to destination server.
command:
sshpass -p password#1 find . -type f -name ""date -d '1 day ago' '+%Y-%m-%d'"" | rsync -avH root#10.31.0.0:/var/lib/edb/as12/data/log .

O correto está abaixo
sshpass -p senha#1 find . -type f -name "data -d '1 dia atrás' '+%Y-%m-%d'" | rsync -avH root#10.31.0.0:/var/lib/edb/as12/data/log .

Related

Using find command to count certain type of executables

I'm trying to use Unix's find command to count the number of executable files in a directory of a certain type, namely Solaris(MSB) executable's. I know I can get the count of all executable files in this directory fairly easy with
find . -type f -perm -u+rx | wc -l
however this doesn't count Solaris(MSB) executable files exclusively. I thought to remedy this I would just throw in a -name flag, something like this.
find . -name "sparc*" -type f -perm -u+rx | wc -l
This will correctly return that there are 6 only if I remove the part of the command that specify's that they need to be executable, if I keep this part of the command it returns a count of 0 which is "wrong". When I look at the ls -l command below I can see that these files are executable I think? or that they are pointing to an executable? This might be the root of the problem.
ls -l
lrwxrwxrwx 1 root other 57 Jul 15 2005 sparc-sun-solaris2.9-c++ -> /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++*
Any insight is appreciated.
Try
find -L . -type f -perm -u+rx | wc -l
or
find -L . -name "sparc*" -type f -perm -u+rx | wc -l
or whatever conditions you need.
Option -L instructs find to follow symbolic links instead of processing the link itself. (see e.g. https://www.unix.com/man-page/posix/1p/find/)
For example with the symbolic link
sparc-sun-solaris2.9-c++ -> /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++*
find should behave as if the file /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++ would be directly located at sparc-sun-solaris2.9-c++
If your find doesn't support option -L you can try -follow like this:
find . -follow -name "sparc*" -type f -perm -u+rx | wc -l

Script fails when using a variable for paths

The following script fails. If I run it manually by giving absolute paths instead of a DIR it works.
#!/bin/ksh
export DIR="/clocal/www/logs/CA"
find $DIR -name "*gz" -mtime +2 -exec ls -lrt {} \;
#Working line : find . -name "*gz" -mtime +2 -exec ls -lrt {} \;
The operating system this is being run under is AIX.

Terminal Command to write mp3 info to text file

I'm hoping to run a command that will get the info from mp3's in a directory and write each MP3's info to a text file with the same name.
Using id3lib to get the MP3 info. This is what I have so far but not working as expected.
This gives me a text file named "{}.txt" with the info
find . -name \*.mp3 -exec info=$(id3info {}); name=({}); echo $info >> {}.txt
Working toward something like this
find . -name \*.mp3 -exec info=$(id3info {}) : filename=$({}); echo $info >> $filename.text : restart ;\
Thanks for any help.
You'd need to execute a shell command as an argument to -exec option. The following might work for you:
find . -name "*.mp3" -exec sh -c "id3info {} > {}.txt" \;
If you also need the mp3 filename to be added to the output, say:
find . -name "*.mp3" -exec sh -c "{ echo {} ; id3info {} ; } > {}.txt" \;

Cron Job - Delete old files, but keep files from the first of the month

I'm currently running successful mysql backups, and, on some sites, I'm deleting files older that 7 days using this command
find /path/to/file -mtime +7 -exec rm -f {} \;
What I'd like to do, because I'm paranoid and would still like some archived information, is delete files older than 31 days, but maintain at least one file from each previous month, perhaps spare any file that was created on the 1st of the month.
Any ideas?
You can also write a script to contain something like this using xargs:
find /path/to/files -mtime +7| xargs -i rm {};
then add the script to your cron job
The grep is almost right, it only has one space too many. This works (at least for me, I use Debian):
rm `find /path/to/file -type f -mtime +7 -exec ls -l {} + | grep -v ' [A-S][a-z][a-z] 1 ' | sed -e 's:.* /path/to/file:/path/to/file:g'`
You can create a file with these commands:
SRC_DIR=/home/USB-Drive
DATE=$(/bin/date "+%4Y%2m%2d%2H%2M")
TIME_STAMP=$(/bin/date --date 'now' +%s)
TIME_CAL=$[$TIME_STAMP-2592000+25200] #last day, 25200 is my GMT+7hour
TIME_LAST=$(/bin/date --date "1970-01-01 $TIME_CAL sec" "+%4Y%2m%2d%2H%2M")
/bin/touch -t ${TIME_LAST} /tmp/lastmonth
/usr/bin/find -P -H ${SRC_DIR} ! -newer /tmp/lastmonth -type d -exec rm -r {} \;
You can modified last command based on what you want to delete, in this case I want to delete sub-folders in SRC_DIR. With the 'time attribute' more than 1 month ago.
Kind of ugly, but you can try parsing the output of ls -l
rm `find /path/to/file -type f -mtime +7 -exec ls -l {} + | grep -v ' [A-S][a-z][a-z] 1 ' | sed -e 's:.* /path/to/file:/path/to/file:g'`
Or write a script to get the list then run rm on them one at a time.

record / monitor asterisk incoming / outgoing calls on mp3

I am using vicidial based asterisk server 1.2 version. I want my asterisk server to record incoming and outgoing calls on mp3 format rather than the default format wav.
Please help
Install sox and libsox-fmt-mp3, in Debian/Ubuntu:
apt-get install sox libsox-fmt-mp3
Put the command below in your crontab:
nice find /tmp -iname "*.wav" -type f -exec bash \
-c 'WAV={}; MP3=${WAV/%wav/mp3}; sox -r 8000 -c 1 $WAV $MP3' \;
My solution for FreeBSD, one-time run the script, and then set up its periodical launch on the crontab:
#!/bin/sh
find /usr/asterisk/recording -name '*.wav' -type f -mmin +180 | while read filename; do
nice -19 lame -h -v -b 32 "$filename" "${filename%.wav}.mp3" && touch -r "$filename" "${filename%.wav}.mp3" && rm "$filename"
done

Resources