Problem With Script
by garethnsolomons from LinuxQuestions.org on (#55F8G)
Hi,
I'm new to Linux and I'm having a problem with a script that I've created. I'm currently on Oracle Linux 7 which is pretty much the same as RHEL 7. I'm trying to create a script to use in a cronjob, which will copy an xml file as well as a directory which was created today. The script should only copy today's folder and xml file - there are multiple files and folders in the folder. I'm trying to use scp (unfotunately I have to use this method). If I run the below script, it does nothing. Doesn't copy any files and doesn't write anything to my simple log file (> /tmp/copybackup.log 2>&1). If I place echo in front of each of the lines, it outputs the following to the log file:
find /dev/dbbackup -type d -name "'AutoFullBackup-20200707*'" -exec scp '{}' root@devln11:/dev/dbbackup/test/ ';'
find /dev/dbbackup -type f -name 'Export-20200707*.xml' -exec scp '{}' root@devln11:/dev/dbbackup/test/ ';'
If I copy this output and paste it in the terminal window, it works perfectly - copies all the right files - but if I run the script... nothing. Please help. Thanks in advance.
Script:
#!/bin/bash
NOW=$(date +"%Y%m%d")
FOLDERTIME='*'
FOLDERNAME='AutoFullBackup-'
FOLDER=$FOLDERNAME$NOW$FOLDERTIME
FILETYPE='*.xml'
FILENAME='Export-'
FILE=$FILENAME$NOW$FILETYPE
find /dev/dbbackup -type d -name '"'"'$FOLDER'"'"' -exec scp "'{}'" root@devln11:/dev/dbbackup/test/ "';'"
find /dev/dbbackup -type f -name ''"'$FILE'"'' -exec scp "'{}'" root@devln11:/dev/dbbackup/test/ "';'"
Please note... I'm running the script as root.


I'm new to Linux and I'm having a problem with a script that I've created. I'm currently on Oracle Linux 7 which is pretty much the same as RHEL 7. I'm trying to create a script to use in a cronjob, which will copy an xml file as well as a directory which was created today. The script should only copy today's folder and xml file - there are multiple files and folders in the folder. I'm trying to use scp (unfotunately I have to use this method). If I run the below script, it does nothing. Doesn't copy any files and doesn't write anything to my simple log file (> /tmp/copybackup.log 2>&1). If I place echo in front of each of the lines, it outputs the following to the log file:
find /dev/dbbackup -type d -name "'AutoFullBackup-20200707*'" -exec scp '{}' root@devln11:/dev/dbbackup/test/ ';'
find /dev/dbbackup -type f -name 'Export-20200707*.xml' -exec scp '{}' root@devln11:/dev/dbbackup/test/ ';'
If I copy this output and paste it in the terminal window, it works perfectly - copies all the right files - but if I run the script... nothing. Please help. Thanks in advance.
Script:
#!/bin/bash
NOW=$(date +"%Y%m%d")
FOLDERTIME='*'
FOLDERNAME='AutoFullBackup-'
FOLDER=$FOLDERNAME$NOW$FOLDERTIME
FILETYPE='*.xml'
FILENAME='Export-'
FILE=$FILENAME$NOW$FILETYPE
find /dev/dbbackup -type d -name '"'"'$FOLDER'"'"' -exec scp "'{}'" root@devln11:/dev/dbbackup/test/ "';'"
find /dev/dbbackup -type f -name ''"'$FILE'"'' -exec scp "'{}'" root@devln11:/dev/dbbackup/test/ "';'"
Please note... I'm running the script as root.