Perl Script – Look For Values – Compress And Send

Hello,

Need a perl script to run on a Linux server that can do this:

1. When a file is detected here: /DMDS/34.Execute-update/send-it-trigger.mvg

• Copy this file: /DMDS/34.Execute-update/TMP/clients.mvg
To: /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.id

The variable DMDSDATUM=$(date ‘+%YYYY-%MM-%DD-%HH-%MM-%SS’)

So the file gets a year-month-hour-minute-day-minute-second file name.

• For testing purposes you can just have anything in that file – /DMDS/34.Execute-update/send-it-trigger.mvg since that file will only exist on my server.

2. Check so this file does not have any white space in it: /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.id

• Test to enter any data into a file and have whitespace in it – if the script works it should remove the white space.

3. Then create these files:

• echo $DMDSDATUM > /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.mvg
• echo $DMDSDATUM > /opt/lampp/htdocs/execute-update/overwrite-update-tmp/last-update.mvg
• echo $DMDSDATUM > /opt/lampp/htdocs/execute-update/overwrite-update-tmp/overwrite.mvg
• echo $DMDSDATUM > /opt/lampp/htdocs/execute-update/overwrite-update-tmp/Update-ID-$DMDSDATUM.mvg

Same as before the $DMDSDATUM variable is: = YYYY-%MM-%DD-%HH-%MM-%SS

4. Then compress all files and folders here: /opt/lampp/htdocs/execute-update/overwrite-update-tmp/*

• Compress all files and folders to a .tar.gz file with a password/encryption.

• I looked into gpg for password protection – but open to suggestion here on what you think is best.

• Also need to have a command line that I can use later to uncompress the file – from a bash script.

• For testing purposes you can put any files/folders here /opt/lampp/htdocs/execute-update/overwrite-update-tmp/ so you can test.

5. Then execute a ncftpput command:

• ncftpput -u test -p test ftp-test.se /0.Incoming /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.tar.gz
• ncftpput -u test -p test ftp-test.se /0.Incoming /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.id
• ncftpput -u test -p test ftp-test.se /0.Incoming /DMDS/34.Execute-update/TMP/$DMDSDATUM-DMDS.mvg

If you don’t have an ftp server to test with – I have one you can use.

6. Last commands:

• Delete folder /opt/lampp/htdocs/execute-update/overwrite-update-tmp/
• Delete all files here: /0.Incoming /DMDS/34.Execute-update/TMP/*
• Delete this file /DMDS/34.Execute-update/PID/in-progress.mvg
• Delete this file /opt/lampp/htdocs/execute-update/trigger/*

7. I want the script to run as a daemon.

8. And it should log to a file what it’s doing.

Good luck – and thanks for help,

Best regards,
Johan

Leave a Reply

Your email address will not be published. Required fields are marked *