cancel
Showing results for 
Search instead for 
Did you mean: 
Post a Question

How to debug script execution

Hi,

I am trying to run my own script via mgmt_cli tool and I am getting the following output:

***

statusCode: "failed"
statusDescription: "/tmp/rconfd-temp-script-iPZGST: line 1: Backup: command not found"
taskNotification: "97c04b63-33f7-4036-b2e0-fc18996077a2"

***

So, apparently there is something wrong (I am importing CP env btw) with the script execution and as far as I can see the tool creates some temp file (/tmp/rconfd-temp-script-iPZGST) that I suppose is exact copy of my script. 

Problem is, that tempt script is automagically removed and I cannot inspect it. How to prevent that? Any command line option? Is some pre-processing made before temp file is generated?

9 Replies
Danny
Pearl

Re: How to debug script execution

Show us your script mate, so we'll be able to better understand what's happening.

Besides that you can easily run: while true; do cp /tmp/rconfd-temp* /home/admin; done; &

in order to copy all temp files to your home dir.

0 Kudos

Re: How to debug script execution

There you go. Nothing too serious. Works fine from command line. 

#!/bin/bash

###########################################################################

BACKUP_FILE=backup_CPSMS_`date +%d-%m-%y_%H%M`.tgz

BACKUP_PATH=/var/CPbackup/backups

BACKUP_COMMAND="/opt/CPsuite-R80.20/fw1/bin/upgrade_tools/migrate export -n"

BACKUP_SERVER='192.168.0.1'

BACKUP_USER='fwadmin'

BACKUP_PASS='********'

###########################################################################

echo `date +%d-%m-%yT%H%M` INFO: Backup script started

cd $BACKUP_PATH

source /etc/profile.d/CP.sh

# Run backup command
echo `date +%d-%m-%yT%H%M` "INFO: Running $BACKUP_COMMAND $BACKUP_FILE"
$BACKUP_COMMAND $BACKUP_FILE
if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "FATAL: Backup command did not complete successfully"
exit 1
else
echo `date +%d-%m-%yT%H%M` "INFO: Backup command completed successfully"
fi

# Test backup file integrity
echo `date +%d-%m-%yT%H%M` "INFO: Testing archive integrity..."
/bin/tar -tzf $BACKUP_FILE > /dev/null
if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "FATAL: Archive integrity test failed. Backup file is corrupt."
exit 1
else
echo `date +%d-%m-%yT%H%M` "INFO: Archive integrity test succeeded. Backup file is good."
echo `date +%d-%m-%yT%H%M` "INFO: Creating checksum file $BACKUP_FILE.MD5SUM"
/usr/bin/md5sum $BACKUP_FILE > $BACKUP_FILE.MD5SUM
echo `date +%d-%m-%yT%H%M` "INFO: Uploading archive to FTP server..."

ftp -n $BACKUP_SERVER <<END_SCRIPT
quote USER $BACKUP_USER
quote PASS $BACKUP_PASS
cd CPSMS
put $BACKUP_FILE.MD5SUM
binary
put $BACKUP_FILE
quit
END_SCRIPT

if [ $? -ne 0 ]; then
echo `date +%d-%m-%yT%H%M` "ERROR: FTP upload failed."
else
echo `date +%d-%m-%yT%H%M` "INFO: FTP upload completed."
fi

fi

echo `date +%d-%m-%yT%H%M` Removing backup file.
rm -f $BACKUP_FILE
rm -f $BACKUP_FILE.MD5SUM

echo `date +%d-%m-%yT%H%M` INFO: Backup script completed

# EOF

0 Kudos
Admin
Admin

Re: How to debug script execution

What's the API/CLI call you're making to the script?

By that I mean the full call.

0 Kudos

Re: How to debug script execution

mgmt_cli run-script script-name "Backup Export" script "Backup Export" targets CPSMS

0 Kudos
Admin
Admin

Re: How to debug script execution

If this is literally what you're executing complete with literally script "Backup Export" as part of your CLI, that's probably why it's not working.

You should probably use put-file (or some other method) to copy the script to the appliance, then use run-script with the script argument calling the full path to the script.

0 Kudos

Re: How to debug script execution

I am trying to backup management server database not the appliance. And if I got it right, if a script is in management server repository it can run on any target with that command, no need to explicitly copy it?

I will try Danny's suggestion today to check what is that temp script looking and why it is not working. 

I have the feeling the empty space in the script name ("Backup Export") is what is making it fail. Devs often forget to escape it Smiley Happy

0 Kudos

Re: How to debug script execution

Well, two findings:

1. Devs do not escape spaces in script names.

2. I renamed script to BackupExport but that did not help.

I managed to capture the temp script and it had only one line "BackupExport". Which does not make any sense. 

So, what am I doing wrong ? 

0 Kudos

Re: How to debug script execution

Why not just that script via job scheduler?

0 Kudos

Re: How to debug script execution

Not recommended by CheckPoint, refer to sk140852

But yes, mgmt_cli will end up in Job Scheduler once I made it to work.