General :: Scripting - Formatting Ps Output W/Perl?
Sep 27, 2010
I'm writing a script that gives me some pertinent info about my servers, and the last little piece I need to figure out is the process list. There are going to be non-technical people looking at the output of the script and I'm trying to make it as simple as possible.
Right now, if I do ps -ef | grep <process> | grep -v grep
It obviously shows me the process, but the problem is that there is 4 lines of info in front of the process. ie
root PID date time java -1024 -cp oh,my,god,there,is,so,much,data,it,carries,on,for,4,lines,I,want,to,shoot,myself,trying,to,read,it,f inally,in,the,end,there,is,a,space /here/is/the/process
I'd like the output to be something like this:
PID: #### Process: /here/is/the/process
I've thought about how I could take the output and use awk or sed but I know there is probably an easier way to do it with perl.
I'm writing a bash script that executes a few perl scripts. One of the perl scripts that I need to execute requires two arguments with it. The arguments are stored in a txt file, each line contains a hostname and its corresponding IP address separated by a ":" (colon), the txt file looks like this below:
[Code]...
I'm not sure if it's the best way to accomplish this but here it goes. In the bash file, let's call it getHosts.sh, I create an array and assign each line of the file to an element in that array. I then think I need to create a new array where I take the hostname (which is before the ":") separate it from its IP address and place the IP address on a new line just below the hostname (this way I can reference to it like $hostNames[$x] would be the hostname, and $hostNames[$x+1] would be its IP address). So the new array would now look like this below:
I'm using the linux 'script' command [URL]... to track some interactive sessions. The output files from that contain unprintable characters, including my backspace keystrokes.
Is there a way to tidy these output files up so they only contain what was displayed on screen?
Or is there another way to record an interactive shell session (input and output)?
I am trying to use awk command in perl. Below is my awk comamnd which works alone. awk '{Easttot=Easttot+$1} END {print Easttot}' MessagesProcessedEAST2Cnts.dat I would like to use this awk's output in shell script. I am using system command like below to get the out put. But it is not working. $Output = system("awk '{Easttot=Easttot+$1} END {print Easttot}' MessagesProcessedEAST2Cnts.dat'");
I want to compare the following two tab-delimited .txt files (both were subsets of the original files) by comparing Columns 3 and 4 simultaneously. It is easy to compare C3 because both C3s are just numbers. But how to compare C4s?Basically, in File1, "G,G" = G in File2, "C,C" = C in File2, "A,A" = A in File2, "T,T"= T in File2.In File2, A/T in Column4 just equals "A,T" or "T,A" in Column4 of File1. C/T in Column4 just equals "C,T" or "T,C" in Column4 of File1, and etc.
I'm writing a Perl script to find an old key in a file and replace it with a new codefirst the program should find the old key in the input file. here is the way I used in my script. but it doesn't work.May you please let me know what is wrong and how I can correct it?the key is stored in the file in the following format:
PHP Code: Key=("1234567" , someOtherVrable) I want 1234567
I'm using Busybox's Hush shell on an appliance running uClinux, and would like to make sure I'm not packing shared libraries that aren't actually used by any application. I couldn't figure out how to compile "ldd" for that environment, but I could compile "readelf" which does the job:
Quote: find /bin -type f -print0 | xargs -0 ./readelf -d File: /bin/myapp Dynamic section at offset 0x7f4c contains 20 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x00000001 (NEEDED) Shared library: [libc.so.0]
I was wondering if it possible to format the output so that I would get something like this instead:Quote:
I have wrote a 1 line command that parses a file, locates the IP Address in the file and then trims the output the way I want it, and then sorts numerically and by uniqueness and then >> appends to output.txt
I can get all the IP's into 1 file "output.txt", but what I am really looking for is some type of way to create a text file, for each IP it finds labeled xxx.xxx.xxx.xxx.txt and also put that ip address into that file..
I have new external usb drive which I'm trying to format to NTFS so I can also use in in windows. I've set it up using fdisk
Disk /dev/sdd: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x604a2a7d
Device Boot Start End Blocks Id System /dev/sdd1 1 60801 488384001 7 HPFS/NTFS
And tried formatting using mkfs -t ntfs /dev/sdd1
However I get the following error Cluster size has been automatically set to 4096 bytes. Initializing device with zeroes: 100% - Done. Creating NTFS volume structures. Error writing to /dev/sdd1: Input/output error. Error writing non-resident attribute value. add_attr_sd failed: Input/output error Couldn't create root directory: Input/output error
I have a perl script that prints an output to standard output using a for loop .It prints a new line every time ,I would like subsequent outputs to be displayed on the same line , I don't want a new line in standard output .Could anyone help plz
Its my first post in here so please be patient I am trying to use regex in perl script to detect allowed words from the file and then print output to the screen.
As an example : I have text file with orders and returns :
My question: is it possible to make sure that i am ony outputing to the screen orders based on few conditions like Item,order form e.g. online.And is it possible to have multiple matches (Item2 only diplay if ordered online etc)
If I use "#!/usr/bin/perl" in the beginning of a perl script the script won't work if the script is at all complicated. Simple scripts like "Hello World" works.
But if I use "#!/usr/bin/perl -w" in the beginning all scripts work?
If I don't use the -w this is whats in the logs:
(2)No such file or directory: exec of '/home/test.net/html/cgi-bin/uh/meny.pl' failed
Premature end of script headers: meny.pl
When I use the -w in the script the error-log shows me this.
meny.pl: Name "main::http_path_cgi" used only once: possible typo at /home/test.net/html/cgi-bin/uh/meny.pl line 24.
I have an command to read inputs from file2 and replace the content in file1. Issue is that the op is coming in a single line as gsub and split functions don't recognize new line characters.
Code: awk 'NR==FNR{gsub(/input./,""); split($0,a," = ");b[a[1]]=a[2];next} {gsub(/@/,"");for (i in b) gsub(i,b[i])}1' $t2 $t3 This gives belwo op:
I've been asked to move data from an old external hard drive to a new one, and to make the new one compatible with the Macintosh. (The old drive's USB connection has died, and I'm connecting to old the drive using a PC card that provieds an eSATA to the drive. The recipient's Macintosh doesn't have a PC card slot, so she can't access the old drive anymore. Hence, the new drive.)
Naturally, I'm doing this data transfer using Linux. I've discovered that I can format the drive as HFS+ using mkfs.hfsplus from the hfsprogs package. But I need to know: do I need to do anything special with the partition table? Is there a special Macintosh partition table format that I need to format this disk to? If so, what tools can I use to get the right format for the partition table?
I bought a 3 TB western digital but I cannot format it. I have to split into 2TB and 1TB (or less because it holds 2.73 TB actually). Is that normal because of linux does not support 3tb yet? I note that I tried into EXT4 and JFS (after tabel creating)
I have a 4 Gb memory stick which used to have OpenSuse on it but I don't use OpenSuse and wanted to use the stick for something else - for backing up my Mozilla Thunderbird installation. I thought that by re-formatting the stick, using a file obtainable from the HP web site, in connection with installing Linux on a memory stick, that it would leave me with an empty one but it hasn't; there is still a lot of OpenSuse stuff on it. How can I "empty" it so that I can use it to transfer my Ubuntu Thunderbird to another computer which is also running Ubuntu. I was going to open a terminal and type:
I am new here and want to lern CentOS. Current I have installed CentOS 5.5 x64 and Perl 5.8.8. Now i have install Perl 5.12.1 which located to /usr/local/bin/perl. But how I can move it to /usr/bin/perl so root based on Perl 5.12.1?
I tried to format my harddisk (160 GB) with the following command
dd if=/dev/zero of=/dev/sda
After some 3 hours, following error came up:
dd: writing to '/dev/sda' : No space left on device 312581809+0 records in 312581808+0 records out 160041885696 bytes (160 GB) copied, 10708.3 s, 14.9 MB/s
I installed openSuSE 11.3. By default, man pages blocks are justified (block-aligned). Example:
Code:
WARNING Improper use of this command may seriously damage your system,so read this manual carefully to understand how to use it correctly and prevent yourself from destroying your system. Instead, I would like all manual pages would be displayed left-aligned, like this:
Code:
WARNING Improper use of this command may seriously damage your system, so read this manual carefully to understand how to use it correctly and prevent yourself from destroying your system.
I definitely would not like to reformat all the manual pages one-by-one. but rather just changing sometnihg in some macro-definition file or something similar? .. Is it possible achieve that simply and quickly?
I have only known about Linux software for the past couple of weeks. I want to install Ubuntu 10.10 on an older desktop I have so I can become more familiar with it. I am average in knowladge about Windows OS and MS-DOS. I tried to install Ubuntu and I get an error message about the harddrive. The CD I am booting with will load on my other PC with Windows XP on it. I have only let it run on it long enough to verify that it is bootable.
I have made a floppy boot disc following the instructions on another Linux site about Ubuntu. I have also tried to boot my alternate PC with the floppy and it boots up. The harddrive on my working PC is a Maxtor 40gb formatted with NTFS file system. The harddrive in the older desktop is a Western Digital 80GB WD800LB-55DNA0.It worked fine with Windows XP on it. I also made a Western Digital DATA Lifeguard for DOS floppy and it boots with it.