- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem with posix script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2003 04:01 AM
тАО10-24-2003 04:01 AM
Problem with posix script
the original series of commands is:
IVO=`uname -s`; if [ "$IVO" != "HP-UX" ]; then echo "Not a HP-UX system...exiting.."; sleep 1; exit 1; fi; echo "Backing up, zipping and emptying syslog.log and mail.log"; cd /var/adm/syslog/; bdf .; for i in *.log; do j=OLD`expr "$i" : "\(.*\).log"`; cp $i $j`date -u +%e-%m-%Y`.log; > $i; gzip -9 $j`date -u +%e-%m-%Y`.log; bdf .; done
If I split this in 2 - it works perfectly -- watch:
itowks02:/var/adm/syslog (root)
itowks02:/var/adm/syslog (root) pwd
/var/adm/syslog
itowks02:/var/adm/syslog (root) ll
total 230
-rw-r--r-- 1 root sys 20080 Oct 24 16:51 mail.log
-rw-r--r-- 1 root sys 9090 Oct 17 23:08 mail.log.Fri
-rw-r--r-- 1 root sys 10038 Oct 20 23:08 mail.log.Mon
-rw-r--r-- 1 root sys 9768 Oct 18 23:30 mail.log.Sat
-rw-r--r-- 1 root sys 9089 Oct 19 23:08 mail.log.Sun
-rw-r--r-- 1 root sys 10040 Oct 23 23:08 mail.log.Thu
-rw-r--r-- 1 root sys 9124 Oct 21 23:08 mail.log.Tue
-rw-r--r-- 1 root sys 9081 Oct 22 23:08 mail.log.Wed
-rw-r--r-- 1 root root 19164 Oct 24 16:51 syslog.log
drwxr-xr-x 2 root sys 1024 Apr 9 2000 trimlogs
itowks02:/var/adm/syslog (root) IVO=`uname -s`; if [ "$IVO" != "HP-UX" ]; then echo "Not a HP-UX system...exiting.."; sleep 1; exit 1; fi; echo "Backing up, zi
pping and emptying syslog.log and mail.log"; cd /var/adm/syslog/; bdf .
Backing up, zipping and emptying syslog.log and mail.log
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 8282112 2097055 5798649 27% /
itowks02:/var/adm/syslog (root)
itowks02:/var/adm/syslog (root)
itowks02:/var/adm/syslog (root) for i in *.log; do j=OLD`expr "$i" : "\(.*\).log"`; cp $i $j`date -u +%e-%m-%Y`.log; > $i; gzip -9 $j`date -u +%e-%m-%Y`.log; b
df .; done
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 8282112 2097033 5798670 27% /
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 8282112 2097011 5798690 27% /
itowks02:/var/adm/syslog (root) ll
total 142
-rw-r--r-- 1 root sys 1038 Oct 24 16:52 OLDmail24-10-2003.log.gz
-rw-r--r-- 1 root sys 1368 Oct 24 16:52 OLDsyslog24-10-2003.log.gz
-rw-r--r-- 1 root sys 0 Oct 24 16:52 mail.log
-rw-r--r-- 1 root sys 9090 Oct 17 23:08 mail.log.Fri
-rw-r--r-- 1 root sys 10038 Oct 20 23:08 mail.log.Mon
-rw-r--r-- 1 root sys 9768 Oct 18 23:30 mail.log.Sat
-rw-r--r-- 1 root sys 9089 Oct 19 23:08 mail.log.Sun
-rw-r--r-- 1 root sys 10040 Oct 23 23:08 mail.log.Thu
-rw-r--r-- 1 root sys 9124 Oct 21 23:08 mail.log.Tue
-rw-r--r-- 1 root sys 9081 Oct 22 23:08 mail.log.Wed
-rw-r--r-- 1 root root 0 Oct 24 16:52 syslog.log
drwxr-xr-x 2 root sys 1024 Apr 9 2000 trimlogs
itowks02:/var/adm/syslog (root)
But if I put them together:
itowks02:/var/adm/syslog (root)
itowks02:/var/adm/syslog (root) IVO=`uname -s`; if [ "$IVO" != "HP-UX" ]; then echo "Not a HP-UX system...exiting.."; sleep 1; exit 1; fi; echo "Backing up, zi
pping and emptying syslog.log and mail.log"; cd /var/adm/syslog/; bdf .; for i in *.log; do j=OLD`expr "$i" : "\(.*\).log"`; cp $i $j`date -u +%e-%m-%Y`.log; >
$i; gzip -9 $j`date -u +%e-%m-%Y`.log; bdf .; done
itowks02:/var/adm/syslog (root) bdf .; for i in *.log; do j=OLD`expr "$i" : "\(.*\).log"`; cp $ <
>
>
> ^C
itowks02:/var/adm/syslog (root)
I think its caused by the number of commands/characters the shell will accept before the next newline - I think I recall running into such a limit before when using C/C++/Pascal.
Syntax is fine (I think) - there is no reason why a string of commands, which works perfectly, followed by another string of commands which work perfectly, seperated by a semicolon, should not work.
It looks as if there is an unmatched quote - I would say this is because the shell only reads so far before (discarding?) the rest. So it might get as far as one quote but discard the second one.
ivo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2003 06:49 AM
тАО10-24-2003 06:49 AM
Re: Problem with posix script
Also, I believe that you have a problem with all this being evaluated as a variable known as IVO.
Your syntax looks fine, however, I count well over 300 characters... if you are trying to pass this output to a variable, I believe there is a 256 limitation on variable assignation.
why dont you simply place your commands in a shell script then export the variable? It seems that will work better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2003 08:32 AM
тАО10-24-2003 08:32 AM
Re: Problem with posix script
Also, keep in mind that there will, eventually, be people other than yourself who will have to maintain these scripts if they aren't one-time runs. You have an obligation to your employer to not obfuscate your work to the point where someone else cannot do it.
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2003 09:07 AM
тАО10-25-2003 09:07 AM
Re: Problem with posix script
thanks again,
ivo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2003 07:48 PM
тАО10-26-2003 07:48 PM
Re: Problem with posix script
Even if you can't or don't want to put scripts onto the server, maybe you have the ability to edit your own .profile?
If so, why don't you code your main processing into a function ? At the end of your .profile, add
function backupandzip
{
echo "Backing up, zipping and emptying syslog.log and mail.log"
cd /var/adm/syslog/
bdf .
for i in *.log
do j=OLD`expr "$i" : "\(.*\).log"`
cp $i $j`date -u +%e-%m-%Y`.log
> $i
gzip -9 $j`date -u +%e-%m-%Y`.log
bdf .
done
}
You can also abbreviate the test clause and your on-liner can then become:
[[ $(uname -s) = "HP-UX" ]] && backupandzip || echo "Not HP-UX ..."
Hope this helps
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-28-2003 01:20 AM
тАО10-28-2003 01:20 AM
Re: Problem with posix script
The best way is to make it an alias or script. It depends on the way you login to the client machine on what your best solution might be. You could, for instance, copy the script to /tmp, run it, and remove it, leaving no rubbish on the clients machine but still do your stuff automatically. If the script is tested well, this will make it a lot saver then to copy-and-past.
Just my 2 cents...