I want to check if files count is 0 on Remote server using ssh.
Below code is only checking if file (ending with .dmp exists )
if ssh v0021x91 ls /apps/oracle/home/DB_1201/*.dmp then echo "Files still exist after cleanup" exit -9991 else echo "Files cleaned up" fi
For below "then" part is executed with $? =0 when actual error "ls: cannot access /apps/oracle/home/DB_1201/*.dmp: No such file or directory"
if [ `ssh v0021x91 ls /apps/oracle/home/DB_1201/*.dmp | wc -l` -eq 0 ] then echo "[INFO ] Dumps Files Cleaned Up on Remote Host" else echo "[ERROR ] issue in Remote Host" exit -9992 fi
I need output of "ls /apps/oracle/home/DB_1201/*.dmp |wc -l" 0 or N number. And if directory is not there (No such file or directory).
Need to return file count 0 or 28 and/or capture directory not found error.
Please advise on the correct approach of executing the SCP and after that validating its status?
Below always returns zero even if some error as its taking local server last command status.
scp -rp /apps/oracle/home/DB_1201/*.dmp oracle@v0021x91:/apps/oracle/home/DB_1201/ if [ $? != 0 ] then echo -e "[ERROR ] Can't copy files from Source to Remote" exit -9995 fi if scp -rp /apps/oracle/home/DB_1201/*dmp oracle@v0021x91:/apps/oracle/home/DB_1201/ then echo -e "[INFO ] SCP Success" else echo -e "[ERROR ] Can't copy files from Source to Remote" exit -9995 fi