I have a need for a portable shell script for LInux and HPUX. The script has a simple need; Check for local files of a specific name (i.e. filename*), scp them to another system, and archive them to a folder. The script runs via cron.
I first wrote the script in Linux (bash with gnu tools) pretty quickly just to get it to function. Then I was asked to do the same type of process running on HPUX (we have 11.31 and 11.23) and did some quick tweaks to get it to run on HPUX. I'm running into issues with the way I wrote it and timing of files written, sent, and archived (I didn't really have the scope of frequency).
Basically I want to put together a portable script with assurances that files will not get 'missed'.
My thought is:
- do a listing of the desired files when the script is run
- If no files, exit
- If files exist, drop the listing into an array
- use the array to send and archive files
Does this sound like the best/easiest way to accomplish this?
The current problem code I have is:
I know this code is not written very well as there is no checks on archiving only the files that were sent.
Any advise on improving for portability and simplifying is greatly appreciated.
echo "\n" isn't portable. Neither is the echo -e some versions of echo require to make \n work. If you want escapes like \n in the string, you must use printf.
Note that it's better to use %s in a printf command string than to substitute variables into it, since you don't want to put more escape sequences into a printf string by accident.
Last edited by Corona688; 04-27-2016 at 06:26 PM..
No, because I tried to keep the functionality.
The $fmask simply allows to specify the "iS*" once at the beginning of the script. The shell will re-evaluate it every time.
But it is no big deal to replace the $fmask by $files for the scp and mv commands.
Then $fmask is evaluated once with the ls command, where the result goes to $files - and that is static.
In an attempt to finally end this article I start this new thread.
Here is a template for a safe and portable script.
#!/bin/bash
# /bin/bash exists on most still supported Unixes
#
# tr and date behave better with
if ; then export LC_ALL=C; else export LANG=C; fi
#
# Unix optional packages... (2 Replies)
I have prepared a shell script to find the duplicates based on the part of filename and retain latest.
#!/bin/bash
if ; then
mkdir -p dup
fi
NOW=$(date +"%F-%H:%M:%S")
LOGFILE="purge_duplicate_log-$NOW.log"
LOGTIME=`date "+%Y-%m-%d %H:%M:%S"`
echo... (6 Replies)
I currently have a shell script that utilizes the "Date" binary - this application is slightly different on OS X (BSD General Commmand) and Linux systems (gnu date). In particular, the version on OS X requires the following to get a date 14 days in the future "date -v+14d -u +%Y-%m-%d" where gnu... (1 Reply)
I'm using solaris 10
Scenario as follows
I have a logfile with 2 columns:
column 1 = source directory + filename
column 2 = destination directory + filename
Using cron, my script polls for new files and adds them to the logfile ($ELOG) as described above. Using sed, the distination... (2 Replies)
Dear Experts,
I want to write a script which has to work on Solaris & Linux sytems.
The problem which i am facing is, there are commands whose options are different on both OS's. For example ping.
On Solaris i have to write:
ping $host 1
to check if the host is alive
On Linux i... (4 Replies)
Hi, everyone:
I post a new thread because previous post may sink and I hope the new one can be caught by your eyes.
I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable... (7 Replies)
I have some scripts that run in Windows, and the ability to put a GUI
layer over them is kind of appealing. So when I stumbled over
http://wizapp.sourceforge.net/ I thought that was rather cute.
(Reading the "advanced batch scripting" art of the manual impresses upon me that no sane person... (2 Replies)
Hi, everybody.
I just wonder whether there are a couple of free Linux servers running as terminals where people can practice Unix Shell Programming?
I'd like to set up one myself but unfortunatly can't do it. I can't switch to Linux now coz I run a couple of servers on my machine.
Cygwin is... (3 Replies)