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.
View 12 Replies
ADVERTISEMENT
Apr 4, 2011
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:
[Code]...
View 4 Replies
View Related
Jan 24, 2011
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)?
View 4 Replies
View Related
Feb 8, 2011
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'");
View 3 Replies
View Related
Mar 8, 2010
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.
File1:
C1C2 C3C4
ih509rs12345467244750"G,G"
ih499rs6049687244911"C,C"
ih508- 7244977"A,A"
[code]....
View 2 Replies
View Related
Apr 1, 2010
pretty simple. how would you background a process from a script and get its process id at the same time?
View 6 Replies
View Related
Oct 13, 2010
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
[code]...
View 1 Replies
View Related
Feb 25, 2011
I'm trying to format the output of ls -l, any help is appreciated
Quote:
[david@barca boot]$ ls
efi
grub
david@barca boot]$ cd efi/
[david@barca efi]# ls
EFI
[david@barca efi]# cd ../grub
[david@barca grub]# ls
device.map
now to long list files in each directory using one line:
Quote:
[david@barca boot]$ ls -l *
efi:
total 2
drwxr-xr-x. 3 root root 1024 May 13 2010 EFI
grub:
total 319
-rw-r--r--. 1 root root 70 Oct 26 17:12 device.map
How can I format the output of ls to get it all in single lines:
Quote:
drwxr-xr-x. 3 root root 1024 May 13 2010 efi/EFI
-rw-r--r--. 1 root root 70 Oct 26 17:12 grub/device.map
Any thoughts?
View 4 Replies
View Related
Jun 19, 2011
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:
/bin/myapp requires: libgcc_s.so.1, libc.so.0
View 2 Replies
View Related
Jan 26, 2011
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..
xxx.xxx.xxx.xxx = the ip address it finds
View 14 Replies
View Related
Feb 12, 2011
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
View 5 Replies
View Related
Jan 26, 2011
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
$count = $hrstorun*60/$intmin;
$interval = $intmin*60;
for ($c=0; $c < $count; $c++ )
[code]....
View 6 Replies
View Related
Feb 22, 2010
Here is some line I have written in perl to show my name :
[code]...
And after stdin kumar, its giving the output as
[code]...
output should be [code]... but why its coming in two lines?
View 2 Replies
View Related
Nov 25, 2010
I am trying to execute a Unix Command in perl and assigning its output to an array:
Code:
@File_List=exec("ls -1 /tmp");
but it is not working. I have tried the perl function system() also but its return code is
[code]...
View 10 Replies
View Related
Feb 18, 2010
The perl script I wrote works fine if I print the result to screen
x0_amber.pl 1 1000 0 5
But whenever I want to output to a file with
x0_amber.pl 1 1000 0 5 > x0_out
it never really prints out to the file.
It worked earlier, but I was playing with my PATH lately, I don't know if it's related to that
View 7 Replies
View Related
Oct 4, 2010
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 :
Item2-SKU-2-11.08.2010-online
Item3-SKU-3-11.09.2010-return
Item4-SKU-4-11.09.2010-store
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)
View 1 Replies
View Related
Dec 17, 2010
I have a small problem with Perl and Apache.
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.
View 1 Replies
View Related
Sep 17, 2009
Is there a firefox add-on to script HTML and/or Javascript directly inside firefox
View 1 Replies
View Related
Mar 7, 2011
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:
[Code]....
View 14 Replies
View Related
Jan 9, 2011
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?
View 1 Replies
View Related
Jun 22, 2011
I'm looking for a way to force my PS1 variable to a certain number of chars.
It currently looks like:
$PS1="W $"
and I'm trying to keep the same number of characters regardless of the length of current folder name.
For example, both Documents and bin would be displayed as 10 character strings, keeping the left side of my terminal the same width all of the time.
View 1 Replies
View Related
Jun 11, 2011
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)
View 1 Replies
View Related
Apr 30, 2010
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:
sudo cp -avr /home/chris/.thunderbird/ /media/disk
I have already tried this but it didn't appear to work, so is this not the right way to go about it?
View 4 Replies
View Related
Jun 29, 2011
I have created one partition. Now I want to extend that partition without formatting it.
View 3 Replies
View Related
Aug 11, 2010
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?
View 7 Replies
View Related
Mar 14, 2010
How do I, in Ubuntu, determine what the formatting (e.g FAT etc.) of an SD card is?
View 2 Replies
View Related
Apr 2, 2010
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
View 2 Replies
View Related
May 6, 2010
I would like to change the formatting on my BASH prompt from this:
anon@machinename.domain.poo:~/some/very/annoying/long/path$
to something like this:
anon@machinename.domain.poo:~/some/very/annoying/long/path
$
The idea is that I would be able to type a reasonably long command on one line without it wrapping to the next line so quickly.
View 2 Replies
View Related
Sep 19, 2010
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?
View 15 Replies
View Related
Jan 22, 2011
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.
View 14 Replies
View Related