The easiest solution I found would be:
[^0]+
The main problem with this is that it doesn't match numbers that begin with a '0' e.g. '0123'. In addition to that it's very general and would match everything that isn't '0' including letters and special characters.
Edit:
Here's the whole script, maybe this helps finding a solution:
search=$(find / -iname _instanceBackup.log 2>/dev/null)
mytail=$(tail -n 14 $search)
mydate=$(date -dyesterday +%y%m%d)
if [[ $mytail =~ $mydate ]]
then
echo "Backup is up to date!"
mytail=${mytail,,}
if [[ ( $mytail =~ 'failed' ) || ( $mytail =~ 'backupexitcode:'[missing RegEx] ) ]]
then
echo "An error has occurred in the backup!"
exit 1001
else
echo "No errors were found in the last backup."
exit 0
fi
else
echo "Backup hasn't run!"
exit 1002
fi
The 2nd if-statement is what I'm trying to do with RegEx. Unfortunately I don't know exactly which backupexitcodes are possible but from recent logs I can say that they are 2-digit numbers that can be negative and can begin with a 0.
$mytail
looks like this:
----------------------------
run_backup.sh(24778) 220222-200037: Instance:user@server:port Schema:"backupname" [Additional Information]
run_backup.sh(24778) 220222-200037: Instance:user@server:port Schema:"backupname" [Additional Information]
run_backup.sh(24778) 220222-200037: Instance:user@server:port Schema:"backupname" [Additional Information]
run_backup.sh(24778) 220222-200037: Instance:user@server:port Schema:"backupname" [Additional Information]
INFO SAP BACKUP UTILITY
INFO Creating backup of server [server:port] in folder [Backupfolder].
INFO Server backup operations finished without error.
run_backup.sh(24778) 220222-200056: Instance:user@server:port Schema:"backupname" [Additional Information]
INFO SAP BACKUP UTILITY
INFO Older backups were deleted without error.
run_backup.sh(24778) 220222-200140: Instance:user@server:port Schema:"backupname" Finish: Timestamp:220222_200037 BackupExitCode:58
----------------------------