Programming :: Bash Shell Scripting / Using The Sort Command To Sort The Top 5 CPU Processes?

Feb 28, 2010

What options should I use when I'm using the sort command to sort the top 5 CPU processes (ps -eo user,pid,ppid,%cpu,%mem,fname | sort ??? | head -5) showing max to min usage?

View 2 Replies


ADVERTISEMENT

Programming :: SORT Command Versus Unix SORT

May 4, 2010

We switched from unix to linux and we have an old report that extracted data from a database, output to an ascii file and then sorted the results in the file based on different arguments. The report now blows up when it runs,and I can only guess it is because the options for sort on linux differ slightly from unix.For example, here is one of the commands issued from within the report app that ran on the old unix box:

if sort-sequence = "descending" then
'sort -t~" -f +3.0f -4.0 +5.0r -6.0 -f '
else
'sort -t~" +3.0f -4.0 +1.0f -2.0 -f'

I will eventually rewrite the report to store the data in a local table, but I can simply adjust the options to suit the requirments of linux. Basically, I need to know if this can be a quick fix for the short term.

View 2 Replies View Related

Programming :: Can't Invoke A Command From Within Shell Script / Sort It?

May 17, 2010

When I try to invoke 'source' command from within a shell script, namely, myscript.sh, I get the following error message code...

View 1 Replies View Related

Programming :: Bash Scripting - Display Real Name From Username Logged In + User Processes?

Jan 14, 2011

i am using putty to connect to the linux server and i am using nano as my text editor to write a bash script.

this is my script:

echo "Please enter your Username"
read userName
userName= grep $USER /etc/passwd | cut -d: -f5
echo "Welcome " $userName | cat >> output.txt

the problem i have is that when i enter my username, the output (my real name) does not display in the output.txt. instead it displays in putty. so when i run my script in putty it shows the message to enter username and after i enter my username my real name appears below it. i want it to show in the output.txt

View 1 Replies View Related

Fedora :: Bash Hangs When Command Not Found / Sort It?

Dec 9, 2009

I've been using linux for a long time, and I just ran into a problem that has me stumped. Any time I mistype a command, it says "Command not found."... yea, I know that's normal. But it doesn't return me to my # prompt. I have to press Ctrl+C to get back. code...

I know I do have one issue with this computer, I have 2 blown caps on my motherboard. This was a dual boot system, but after a virus with winblows, I decided to switch it to strictly linux. (roommates... *grumble*) I think I was running fc10 before I wiped the hd & installed fc12. Fc12 does seem to be running slower, and I still haven't got my sound card working properly... but that issue is for another topic...
-YungBlood Reborn

View 2 Replies View Related

Programming :: Sort IP Addresses For A Bash Program?

Apr 29, 2010

I have for example the following IP addresses:

24.172.220.218
41.239.36.19
63.215.202.234
66.176.124.22

[code]....

How can I sort those IP addresses? I want to sort them using the first 3 numbers I also want to count the number of times that address is repeated This is a batch program.

View 4 Replies View Related

Programming :: Bash Script: Sort Files Into Directory Based On Data In The File Name?

Sep 28, 2010

I have very little linux experience. And need some help with a bash script. I need to a script I can set cron to run to sort files out of a holding folder into final folders. It doesn't necessarily have to be bash, but I think it would be sufficient for this. File names are formatted as such when created: Dest-Date-Time-CID-Destination# I want the files to be moved from a all in one holding folder to a folder structure like this.

.../storage/year/month/day/Destination#/VarX(type)/hour/CID/'File'

I would need an if/else if/else statement to say if Dest = A set VarX = B If for example the file name was

infinity-20100927-17:00-1112223333-4445556666.wav

I would like the above file to end up moved from

.../holding

to

.../storage/2010/09/27/4445556666/Inbound/17/1112223333/infinity-20100927-17:00-1112223333-4445556666.wav

So the script will need to make directories based on information in the file name which is delimited by single dashes. Then move files from the holding folder to the newly created "sorted" folders.

View 15 Replies View Related

Programming :: Sort Of Execv Command Needed?

Jul 2, 2010

I have a problem, I need to launch another binary from my application, but I need to get the control back once the other binary is initialized. fork/exec doesn't seem to give anything on that side using pthreads I'm able to wait until the new thread exits, but that's not what I want at the moment I'm using popen, but it doesn't seem to do the job right...

View 14 Replies View Related

Programming :: Sort Command Output Differs When Encounters?

Mar 18, 2010

Here is what I am doing I have a file, a.txt for example, with following contents:

Code:
coreutils install
cpio install
cpp install
cpp-4.3 install
dbus install

[Code]...

So it seems like the sorting algo. for dpkg --get-selections is different than sorting algo. of 'sort' command when it encounters "-" (hyphen). How can I sort the original file (a.txt) in such a way that it produces the output file ,b.txt, exactly the same.

View 6 Replies View Related

Programming :: Shell Scripting Loop Error Yal2361: Command Not Found?

Jul 22, 2011

I have written the following script in my linux server to add users for LDAP database.But i can't able to run this.

The script is as following

#!/bin/bash
echo "Mention the username which you want to convert LDIF format"
read username
if ["$username" -e "/ldiffile/passwd"]; then
echo "Username already exists"
else
cat /etc/passwd | grep -i "$username" >> /ldiffile/passwd
fi
The output which i got :
. ldapadd.sh
Mention the username which you want to convert LDIF format
yal2361
-bash: [yal2361: command not found

please let me know where need to change and what

View 5 Replies View Related

Programming :: BASH Sort List By End Of Line To X Position In Each Line?

Aug 18, 2010

I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:

Code:

while read 'line';
do
sp=$(echo $line)
vc=$(echo $sp | cut -d"," -f1)
cv=$(echo $sp | cut -d"," -f2)

[code]....

Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a

Code:

q=$(expr length $line); echo $q
n=$[q-8]; echo $n

kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.

View 14 Replies View Related

General :: Bash Shell Scripting Request?

Feb 27, 2011

I am working on a simple script that should take two command line arguments, a [number] and a [name]. The first thing the script should do is check to make sure that no more and no less than two command line arguments have been entered when calling the script - an error message should be delivered if the condition is not true.

If two args have been entered, then the message 'processing "scriptname"' should appear, where scriptname is the name of the script being called. The script should then write to the screen "Hi [name]!", and should write this phrase [number] of times. For example, the command $ myscript 2 joe would produce the output: I have read the manual many times looking for examples, and I am very close by virtue of my own efforts. Further, I have searched these forums and others for good examples, which have also gotten me very close. Still my script is not completing the objective, and I am wondering if someone could point me in the right direction. Script:

[Code]...

View 13 Replies View Related

Programming :: Shell Scripting / Create A Shell Script Similar To Ls?

Jun 5, 2011

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.

Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....

View 10 Replies View Related

Ubuntu :: Using Bash To Sort Csv-files?

Jul 25, 2011

I am in need of sorting the content of a csv-file separated with "#". The file looks the following:

Code:
Descriptive 1#47.5498295127948#35.5365757501888#44.4127802931231#84.0767444257134#0.0416435951243528#0

[code]...

View 8 Replies View Related

General :: Using Sort And Uniq In Bash?

Feb 18, 2011

I have this file with the first lines as follows:

a
a
ability
able

[code]....

say the file is named file1.txt After i do the following:

sort file1.txt | uniq >> file2.txt

I expect that letter a would only appear once, not in two rows, word about would also appear only once. However, I can't seem to get that result using this. I also tried the sort -f file1.txt | uniq >> file2.txt but to no avail. I actually got file1.txt from a messier file using the -f option in sort command.

View 2 Replies View Related

General :: Write Either PYTHON Or Bash Shell Scripting?

Jun 4, 2010

I do not know how to write either PYTHON or Bash Shell Scripting. I am to learn one for Linux Administration purpose. Which one will you recommend for a Linux Admin/Eng environment?

View 4 Replies View Related

Server :: Bash Shell Scripting For Samba Configuration?

Apr 5, 2011

vi /etc/samba/smb.conf
[samba test]
comment = client
path = /opt/apps/deploy/websites
public = no
writable = yes

[Code]...

Using the bash shell script the above given samba configuration,the script should automatically add these above given entries in the /etc/samba/smb.conf.can any one help me how to edit the file add entries in the config file using shell script.

View 10 Replies View Related

Software :: Unable To Install Gnome Shell / Sort This?

Mar 13, 2011

Unable to install gnome shell.
using ubuntu 9.10.
tried both way, terminal and ubuntu s/w center.
"Unable to fetch......" error occurs.

View 3 Replies View Related

Software :: [blah]$ Somecommand - Which Shell Has This Sort Of Layout

Jan 13, 2010

I forget which one it was, but the prompt looked like this:

Code:

[blah]$ somecommand

Which shell has this sort of layout?

View 8 Replies View Related

Programming :: Creating Array From Command Output (Bash Shell Script)

Jan 26, 2011

I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct

So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/

Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.

View 5 Replies View Related

Ubuntu :: Bash To Sort Files Into Subdirectories?

Sep 4, 2010

i currently have hundreds of files all in a single directory. What I would like to do is create 8 subdirectories and move the files into the subdirectories based on the first character of the file name. Ideally, the script would omit any 'the' or 'a' and use the second word for filing purposes. No filenames have spaces. Instead they use periodsThe subdirectories will be:

0-9
a-d
e-h

[code]...

View 2 Replies View Related

Software :: Crond Not Starting Shell Based Apps / Sort This?

Nov 17, 2010

I tried using cron to start rtorrent. But I couldnt start it successfully. My crontab looks like this.

Code:
# m h dom mon dow command
40 22 17 11 * rtorrent
My cron is running properly. How could I start a new shell , so that rtorrent could run using cron.

View 2 Replies View Related

Programming :: Global Bash Shell Functions - A.sh: Line 2: Echotm: Command Not Found

Sep 13, 2010

I wonder if there is anyway to make a user-defined bash shell function global, meaning the function can be use in any bash shell scripts, interactively or not. This is what I attempted:

Code:

$ tail -n 3 /etc/bashrc
echotm () {
echo "[`date`] $@"
}

[code]....

View 11 Replies View Related

Programming :: Perl About System Command / Fails If The Standard Shell Is Dash And Not Bash?

Jun 30, 2011

I am trying to fix a perl script, and I really suck at perl. But I think this problem will be easy for people who know it.

The problem is, I have an old setup script someone wrote many years ago. It fails if the standard shell is dash and not bash. The only way I've gotten it to work is to point /bin/sh to bash. I looked thru the script and it uses "system" many places, and I think that's the problem.

I searched for it and found this link:url

My plan is to include this function:

Code:
sub system_bash {
my @args = ( "bash", "-c", shift );
system(@args);
}
Then I could simply change all calls to system into system_bash and it should work?

The parameter to the system calls is usually some variable. What if the parameter is a list already? Do I need to test for it somehow, and if it's a list, prepend "bash" and "-c" to the list? How do I do that?

In the script there are lots of places like this:

my $error = system($cmd);
if ($error) {
die/warn "some error message";
}

Shouldn't there be a return in the system_bash function?

View 8 Replies View Related

Programming :: Bash Shell Read User Argument From Command Line And Test It

Aug 29, 2010

Trying to create a small script that will read user's input, test if user entered some input and if not display some message or display a text using user's input.

The script is the following but i get an error saying "[: 6: =: argument expected"

View 12 Replies View Related

General :: Bash - Merging Strings (perhaps With Sort | Uniq)?

Nov 16, 2010

I have multiple strings (eg. say two, firstLIST=(0 1 2) and secondLIST=(2 3)) and want to create a single string composed of their unique sorted elements. For the sample strings above, I'd like to build masterLIST=(0 1 2 3).I suppose I could write the elements of firstLIST and secondLIST to files

Code:

echo ${firstLIST[@]} > firstFILE
echo ${secondLIST[@]} > secondFILE

then use

Code:

sort firstFILE secondFILE | uniq > masterFILE

as this gives me a file populated with the elements I'm after, but I'm not sure how to read the elements back into masterLIST... and it doesn't seem "right" to create files to accomplish this. Is there a way to do this by manipulating the strings ${firstLIST[@]} and ${secondLIST[@]} directly? The closest I've come (not close at all) is

Code:

masterLIST=${firstLIST[@]}" "${secondLIST[@]}

but masterLIST built this way has only one element

Code:

$echo ${masterLIST[@]}
0 1 2 2 3
$echo ${#masterLIST[@]}
1

and I don't have access to the individual digits to then try to figure out how to remove duplicates.

View 4 Replies View Related

Fedora :: Shell Scripting / Bash Error Est.sh: Line 9: Kill: (20831) - No?

Jun 11, 2010

I was giving the found the following shell script. I was told it was suppose to ensure only that only one script of Test.sh can run..

However, I get it looks like it has a error when i run it... As i get Test.sh: line 9: kill: (20831) - No such process

what is going on in this script can someone explain it to me... I thought it suppose to work like a singleton for my script creating a file .run-test-sdolan. However, i don't see how or where .run-test-sdolan is create?

sdolan@staging:$ vi Test.sh
#!/bin/sh
MYDIR=`dirname $0`
CONFDIR=$HOME/
code....

View 4 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Fedora :: Create A Shell Script File With Two Functions - Bash Scripting & /etc/bashrc

Oct 6, 2010

how come I can create a shell script file with two functions, I can execute the file, but when running declare -f, the functions are not on memory, and when invoking the function bash returns invalid. In the other hand, I can copy & paste the two functions at the end of my /etc/bashrc file.... then I can called the function by name.... and the commands within that function run on my session. here is a print of all my bash packets:

[Code]....

Does Fedora has restrictions on shell scripting? I haven't touch bash in seven years, so if things have change on it I'm behind on it, and sorry for my ignorance.

View 1 Replies View Related

General :: System Administration Scripting - Write Very Basic BASH Shell Scripts

Jan 10, 2011

I'd like to know some good resources, links, e-books to learn basic Linux system administration scripting. I know how to write very basic BASH shell scripts so I'm still at beginner level. There are so many docs out there that I'd like to narrow down people's opinion's on the best easy to understand resources that are available. Eventually I'd like to learn basic PERL as well.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved