Operating System - HP-UX
1752290 Members
4613 Online
108786 Solutions
New Discussion юеВ

Re: How to send shell .sh history file in email in right format ?

 
Sammy_2
Super Advisor

How to send shell .sh history file in email in right format ?

Trying to email .sh history file. Was able to convert to spaces using tr command below. But in my email , I see first few commnads appear correctly as one line each but then they start comming all in one line (like after crontab -l command). See below the .sh file output and part of the script as well.

How to fix it.? thx



===========================================
# translating some non-ascii char to space ##that was causing email problems ##
#!/bin/ksh
file=".sh__root_tibco_3111_09:28:08"
cat ${file} | tr "\201" "\040" >> emailbody
cat emailbody | mailx -s "`uname -n` on `date`" $MAILADMIN
===========================================

.sh__test_tibco_3111_09:28:08
=============================
ps -ef|grep hawk
kill -9 23008 22924
ps -ef|grep hawk
cd /app/tibco
cd log
ls -la
tail -f strtadmin.log
ls -la
tail -f notification.log
crontab -l
/usr/ucb/ps -auxww|grep NotificationDBAgent|grep -v grep kill -9 18298 /usr/ucb/ps -auxww|grep NotificationDBAgent|grep -v grep ls -la cd /app/tibco ls -lka ls -la cd adapter ls -la тАЪ cd adadb ls -la cd 5.2 ls -la cd odbc ls -la ls -la cp odbc.ini odbc.ini20100517 cat odbc.ini more odbc.ini ls -la crontab -l cd /app/tibco/bin/strstp ls -la cat recycle.sh crontab -l recycle.sh daily_stop crontab -l ls -la cat recycle.sh ls -la cat strstpAdbAgent.sh ls -la cat strstpTibco.sh crontab -l ps -ef|grep acco


good judgement comes from experience and experience comes from bad judgement.
7 REPLIES 7
Tingli
Esteemed Contributor

Re: How to send shell .sh history file in email in right format ?

Maybe you need to run unix2dos first. See man unix2dos for details.
Steven E. Protter
Exalted Contributor

Re: How to send shell .sh history file in email in right format ?

Shalom,

Do what you need to parse your output to a single file.

Then: http://hpux.ws/mailfile2

It is a good file attachment sender. Well tested.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: How to send shell .sh history file in email in right format ?

The shell history file is full of binary chars at the beginning.
You can see them with: vis $HISTFILE
Sammy_2
Super Advisor

Re: How to send shell .sh history file in email in right format ?

I can vi it but with email to ms-exchange it does not like it.
unix2dos did not work but I am testing more.
thks for attachment for email but I am wondering if someone is email themselves shell history and if it looks ok in email.
Thanks for all.
good judgement comes from experience and experience comes from bad judgement.
Bill Hassell
Honored Contributor

Re: How to send shell .sh history file in email in right format ?

The problem isn't email...you are trying to look at a binary file and you have no control over the special codes that are imbedded in the file. Try using these commands:

strings .sh_history | vis | mailx -s "`uname -n` on `date`" $MAILADMIN

Your filter program is fixing only one of dozens of possibilities for binary characters. The strings command will extract what appears to be ASCII strings (but they could contain special characters) and vis will expose them using \000 where 000 is the octal code for the special character.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: How to send shell .sh history file in email in right format ?

Hi Sammy:

As Dennis and Bill have noted, the history file contains binary data. In particular, NUL characters delimit the commands. I can recreate your problem and can fix it (if you don't mind double-spaced output) thusly:

# perl -pe 's{^\000+}{\012}' /root/.sh_history|mailx -s "Your History File" you@your.net

Regards!

...JRF...

nightwich
Valued Contributor

Re: How to send shell .sh history file in email in right format ?

Hi Sammy

You have a simple way to achieve this.


Connect to the unix machine to winscp. Copy the .sh_history_file. Check it with wordpad and if ok and need to send it to someone help, hust do it ..


Regards.