0

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"<!-- /wp:paragraph -->  <!-- wp:codemirror-blocks/code-block {"showPanel":false,"languageLabel":"no","mode":"clike","mime":"text\/x-c++src"} --> 				<div class="wp-block-codemirror-blocks-code-block code-block"><pre>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   </pre></div><!-- /wp:codemirror-blocks/code-block -->  <!-- wp:paragraph -->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).<!-- /wp:paragraph --> <!-- wp:paragraph -->Need to return file count 0 or 28 and/or  capture directory not found error.<!-- /wp:paragraph --> <!-- wp:paragraph -->Please advise on the correct approach of executing the SCP and after that validating its status?<!-- /wp:paragraph --> <!-- wp:paragraph -->Below always returns zero even if some error as its taking local server last command status.<!-- /wp:paragraph -->  <!-- wp:codemirror-blocks/code-block {"showPanel":false,"languageLabel":"no","mode":"clike","mime":"text\/x-c++src"} --> 				<div class="wp-block-codemirror-blocks-code-block code-block"><pre>   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 [email protected]:/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

Regards, Veera