JeoSaurus 32 Posting Whiz in Training

My advice? Try them ALL! At least the mainstream ones. Most everything else is based on one of the mainstream distros. It's all a matter of preference. I started out with RedHat and rpm dependencies drove me nuts... Found Debian a few years later and fell in love with their apt package manager.

Most distributions these days come with a live cd so that you can try them out without even having to install them on a hard drive. Some of the ones that I would recommend you start with:

Ubuntu
OpenSuse
PCLinuxOS
Fedora
Xandros

I believe all of these (except maybe Xandros... It's a commercial distro, with a stripped down free version) have live CD or DVD versions available.

Hope this helps! The thing that makes this question so hard is that Linux can be anything you WANT it to be! With very little experience, you can take just about any distribution out there and make it as windows-like as you want.

-G

JeoSaurus 32 Posting Whiz in Training

Doesn't tripwire write a to a report file by default? Maybe you could get the results you're looking for by running tripwire and then parsing the report?

Otherwise, I think you're just missing some quotes to hold everything together ;) Try this!

#!/bin/sh -e

tripwire=/usr/sbin/tripwire

[ -x $tripwire ] || exit 0

umask 027

tripResult="$($tripwire --check --quiet)"

tripViolations=$(echo "$tripResult" | awk '/Total.violations.found/ {print $4}')

exit 0

(I took some liberties with your grep|awk arrangement... why use 2 cmds when one will do! ;)

Another way to do this would be with a temporary file, like Salem said. You could do something like this:

#!/bin/sh -e

tripwire=/usr/sbin/tripwire

## configure the log file as a variable
logfile=/tmp/tw.log

[ -x $tripwire ] || exit 0

umask 027

$tripwire --check --quiet > $logfile

tripResult=$(cat $logfile)

tripViolations=$(awk '/Total.violations.found/ {print $4}' $logfile)

rm $logfile

exit 0

Or you might want to choose to keep those log files, and timestamp them.

logfile=/tmp/tw-$(date +%D-%T).log
# comment out the 'rm' at the end ;)
# rm $logfile

I hope this helps! Sorry if that's too much info... or not enough...

-G

JeoSaurus 32 Posting Whiz in Training

Does that happen after you log in, or during boot up?

JeoSaurus 32 Posting Whiz in Training

It's all about what you're comfortable with!

Linux can be point-and-click, or you can do it all at command line. I'll also say that if you're running Linux as a web server (with php/mysql/whatever) with light to medium traffic, hardware specs aren't really an issue (I mention this since you were talking about purchasing a server). I have a colocated Linux server running ~70 domains on a Pentium 3 with 512 MB of RAM :) That includes web traffic (php/perl/mysql/etc) email, ftp, irc, and shell (for trusted users) services!

Windows offers the point and click interface, true, but the way IIS works isn't that intuitive to me. But if that's what you're familiar with, I'd say go for it. For the application that it sounds like you're talking about, though, I think Linux offers more "bang for the buck".

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

BillBrown hit it on the head. It's really all about preference. I started out working with RedHat servers, and then experimented with every different distribution I could get my hands on until I discovered the beauty and elegance that I like to call "apt" (the package manager used by Debian (and debian-based distros)).

I use Debian for all my server applications, and xUbuntu for my desktops. BUT it's all about preference.

In my personal experience, Debian makes a reliable, easy to manage (if you're comfortable at the command line) server. There are also graphical configuration tools, but I'm not that familiar with them, so I don't know how a new user would find them.

If you're not that familiar with Linux yet, and want a shiny web-based interface to help you get things set up, the "SME Server" distribution is really nice (or it was the last time I used it, at a previous job). Especially if you're running it in mixed (Windows and Linux) environment.

RedHat/CentOS based distributions are also very stable, but their package repositories are not nearly as complete as Debian's, and trying to resolve rpm (the redhat package manager) dependencies manually can be a nightmare. But they do provide some nice graphical configuration utilities if you are planning to run a graphical desktop on your server.

Fedora can also be used as a server, but it's the "bleeding edge" RedHat distribution, and in my experience is not stable enough for a …

JeoSaurus 32 Posting Whiz in Training

This may be late, but I wanted to get the "column" command into the fight!

$ column -t -s " " test.txt 
aba   bba   baba
abba  baba  baaa
addd  ffff  fffff

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hi Ajay!

I'm not that familiar with Java, so are the System.out messages what gets printed on the command line?

If' so, you'll want to run your java app like this: ./java-app >> log.txt Seems like I read a similar post, and someone was having trouble getting the error messages that way, so you may want to redirect stderr to stdout for logging purposes. Like this! ./java-app >> log.txt 2>&1 Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Okay, I think I'm confused now. It sounds like you just need to run that file as a shell script.

# sh ./file

Unless there's a reason to run it line-by-line... If you can't run it in place like the above example, you might want to copy it off to another file and execute it there. To do it using our original example:

cat /path/to/file |while IFS= read command; do
  echo "$command"
done > /tmp/script.sh

sh /tmp/script.sh

I'm not sure if you can run it line by line. I was originally thinking you were using stand-alone commands, instead of running multiple commands together and setting variables. Hope this helps!

G

JeoSaurus 32 Posting Whiz in Training

Hi Jaoqua!

How have you tried so far? Depending on how the file is formatted (are there spaces in some of the commands you want to run?) it should be as simple as: for i in $(cat /path/to/file); do $i; done If there are spaces in the command lines that you want to run, it'll get a little more complicated. You'd have to do something like this to change the Internal Field Separator temporarily, or else each line will be broken into a new command at every space:

cat /path/to/file |while IFS= read command; do
  $command
done

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hi Manik, you might want to start a new thread, since this was was solved back in March :)

If this isn't what you're looking for, please start a new thread with more details. From what you've given us so far, it sounds like you just need to do something like: grep Timeout /opt/---/---/NodeA/logs/Server_name/SystemOut.log Not very exciting, but should do the job unless you need it to do more.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

This is a really interesting project. I'd like to take a deeper look into it when I have some time :)

Although I love bash a lot, Perl has a lot of built in functions to handle the conversions you're trying to do. I'm not that good with Perl personally, but I know that some of what you're doing here might be a lot simpler in Perl. Just a thought :)

-G

JeoSaurus 32 Posting Whiz in Training

OR you could break it up into functions!

Make each part of the script into a function, and you can go back to whatever function you want at any time.

For example, you can turn that initial prompt into a function:

prompt () {
echo "Please enter a file to sort: \c"
read filename
}

Then you can go back to that function by calling "prompt", say for instance in place of "exit" if the file test or read test fails.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hi Nick,

We'll need a little more info to help you I think. You say you know about mysqldump, so I assume you just need to know how to script a mysql dump for each database?

If that's the case, you can do something like this:

#!/bin/sh
# First let's get a list of databases, and 
# loop through the results.  This mysql
# command will list all databases in the 
# instance.  
for i in $(mysql -uUSER -pPASSWD -B -e 'show databases'); do

# Next run your mysqldump
  mysqldump --user=USER --password=PASSWD $i

done

If you want to dump all databases, just run mysqldump -A --user=USER --password=PASSWD You can also substitute the mysql command in my for loop with something that will provide a list of just the databases that you want ot back up, if you don't want them all. A text file would probably be easier. One database per line. You could then change that "for" statement to something like this: for i in $(cat database.list); do I hope this helps! Show us what you've got so far and we might have a better idea of how to help :)

-G

JeoSaurus 32 Posting Whiz in Training

Hi Rast,

To do this with find, try the -cmin switch:

-cmin n
              File’s status was last changed n minutes ago.

EDIT: Or you might be looking for this one:

-mmin n
              File’s data was last modified n minutes ago.

(I got this from the man page for find btw. This might be a new feature... haven't researched it that far yet.)

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

If all that's in that directory is the sym links to the files that you want to tail, try something like this: for i in $(ls /path/to/directory); do tail -n 21 $i; done Let us know how it goes! If we're missing the gist of what you're trying to do, post your script for us so that we can get a better idea!

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hmm... well, technically you could run it all on one line like this: for FILE in $(find . -type f -name '*4%3a*'); do NEWNAME=$(echo $FILE|sed s/'4%3a'//); mv -v $FILE $NEWNAME; done but that's kind of ugly :-P

What we have here is called a shell script. What you'll probably want to do is paste the script from above into a text file. Name that text file "myrename.sh" or something easy to remember. Copy it into your ~/bin directory, or if this is a temporary project, save it in the directory where all those files live, and execute it like: $ sh /path/to/myrename.sh I hope that's not too confusing.
-G

bimaljr commented: Perfect sollution +2
JeoSaurus 32 Posting Whiz in Training

Hi k2k,

There are a few options. Usually, if you're the root user, these things are in your "PATH". Are you by any chance logging in as another user, and using the "su" command to get to root? if so, try using "su -l". This will start a login shell, and import all of root's default paths.

If a command is in your path, you can use the "which" command to find the full path if you need it. In your case, it looks like things like /sbin and /usr/sbin are missing from your path. If you've got slocate installed, you can use the "locate" command to find most things.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Forgot to add comments!

#!/bin/sh

# first we need a list to work from.  the
# "for" statement will loop through the results
# of our "find" command, using each result in turn
# as "$FILE".  The find command that I used will
# recursive look in subdirectories as well.  You can
# fix that with a flag, or you could use something
# like `ls |grep '4%3a'`
for FILE in $(find . -type f -name '*4%3a*'); do

  # here we use sed to get rid of the unwanted string
  # and store it as "$NEWNAME"
  NEWNAME=$(echo $FILE|sed s/'4%3a'//)

  # here we do the actual work!
  mv -v $FILE $NEWNAME

done
JeoSaurus 32 Posting Whiz in Training

Usually we use the "mv" (move) command to rename a file. Try something like this!

#!/bin/sh

for FILE in $(find . -type f -name '*4%3a*'); do
  NEWNAME=$(echo $FILE|sed s/'4%3a'//)
  mv -v $FILE $NEWNAME
done

If the files are all in one directory, you can run this from in that directory and it should get all of them. It's very basic, so if you run into any problems let us know. It worked on a test run with files formatted like your example.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Okay, so this seems to be from 11 days ago. Have you gotten it resolved yet?

I've seen this happen on AIX (I think it was) and it turned out to be a problem with a library that needed to be updated. May I ask why you're using compress rather than gzip? Compress is more widely used in Unix applications than in Linux.

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training
JeoSaurus 32 Posting Whiz in Training

Yeah, haven't worked with Xen much myself. That could be it! Let us know what you find :)

-G

JeoSaurus 32 Posting Whiz in Training

I poked at your original script and made some syntax changes to your "if" statement. I think it does what you want now. I think you have to use brackets when doing a comparison like this:

$ cat daniweb.sh 
#!/usr/bin/bash
memUsage=$(ps -C bash -o pid=,size|awk '{SUM += $2} END {print SUM}')

echo "total usage is: $memUsage"

if [ "$memUsage" -gt 65536 ]; then
echo "mem usage exceeded"
else
echo "mem usage normal"
fi
exit 0

I played with different numbers in the if statement, and it seems to do the job.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Try this! ps -C bash -o pid=,size | awk '{SUM += $2} END {print SUM}' The problem is that your awk statement doesn't have a "print" command. You have to tell it what to print.

I also took some liberties in my example, and used some built in functions of PS rather than piping it through grep ;) The output of that ps statement is the pid and memory usage (in KB, so the final answer is also in KB)

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Are you sure you don't just have to run the .bin file? I've seem some software packaged as .bin or .run. These are usually install scripts that extract their own rpms (or binaries, or source, or whatever) and install them.

JeoSaurus 32 Posting Whiz in Training

Hi Mike,

That's certainly an odd problem... Let's compare the output of these commands:

$ date "+%a %d %b %Y %X %Z"; hwclock; ntpdate pool.ntp.org

That'll tell us if there are any differences between the system clock and the hardware clock, and give us a baseline from ntp. Do you know if the hardware clock is set to local time or UTC?

JeoSaurus 32 Posting Whiz in Training

Here's another problem:

"however, the dyndns.com auto detector detects another ip, i have to manually change it to 192.168.1.5 so i can do ssh at home"

dyndns is detecting your "public" ip address, which is the one that you would use to connect to your home network from the internet side of thigns. You'll want to use the one that dyndns autodetects, which will get you to your router, and in your router, you'll set up port forwarding to forward SSH on the public IP to the SSH port on that server inside your network.

The problem with this is that you won't be able to use that dyndns hostname to connect from the local network. Actually... you SHOULD be able to do it that way, you're just going out to the internet and coming back in. Yeah! that should work as long as your dyndns hostname is pointed to the public IP and your router is routing SSH traffic to the 192.168.1.5 IP on your local network.

I hope that isn't too confusing... I'm never good at explaining network routing stuff :)

-G

JeoSaurus 32 Posting Whiz in Training

Nice! Looks like fun ;)

JeoSaurus 32 Posting Whiz in Training

There are thousands of ways to do this one :) Try this! grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' /var/lib/output Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

Here's a test I wrote just to see if my math was right :)

#!/bin/bash

if [ -z "$1" ]
then
  echo "Usage: $0 <hex#>"
  exit
fi

TEST="$1"
HEX=$(echo -n ${TEST:2:4}${TEST:0:2})
#DEC=$(echo "ibase=16; obase=10; $HEX" |bc)
DEC=$(( 16#${HEX} ))
RESULT=$(( ${DEC}/8 ))

echo "Input was: $TEST"
echo "Rearranged to: $HEX"
echo "Converted to dec: $DEC"
echo "Divide by 8: $RESULT"

Works with your example, and gives the same results. Hope this helps!

-G

JeoSaurus 32 Posting Whiz in Training

That's an interesting one... is the pattern for each one the same as your example?

If so, you could do something like:

TEST=(A028) ; echo -n ${TEST:2:4}${TEST:0:2}

Maybe? I dunno...

-G

JeoSaurus 32 Posting Whiz in Training

Hi!

I think Rad' meant to put quotes around the variable, like "$1". I don't think that's going to help though. This problem used to frustrate me so much!

Okay, I'm not sure how this will translate to what you're doing because I don't know java, but I usually get around this in bash with "read". Here's an example... I start with a test file that has multpile lines with spaces:

$ cat test.txt 
hello kitty
scooby doo
mighty mouse
casper the friendly ghost
yogi bear

We can read lines out of this file with something like "cat", but we'll have the same problem you're seeing which is that each line gets broken into a new line at the spaces:

$ for i in `cat test.txt`; do echo "$i"; done
hello
kitty
scooby
doo
mighty
mouse
casper
the
friendly
ghost
yogi
bear

To get around this, we can use "read" in a loop:

cat test.txt |while read LINE; do 
  N=$((N=1))
  echo "$LINE"
done

This gives us the output that we want. For your script, you might try something like changing the IFS (Internal Field Seperator) variable (and changing it back when we're done):

OLDIFS="$IFS"
cat test.txt |while IFS= read LINE; do 
  echo "$LINE"
done
IFS="$OLDIFS"

So, like I said, I'm not 100% sure how this would work in your script, but here's a few things to try!

Thanks,
-G