JeoSaurus 32 Posting Whiz in Training

Well both of those methods are imperfect for counting connections, but you're probably getting a more accurate result with grep in this case, because it won't count the first two lines (if your output is like mine)

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State

Also consider that the result may actually be different from one moment to the next.

Here's perhaps a more accurate way to do it:

echo "TCP Connections: $(netstat -ant|awk 'END {print NR-2}')"
echo "UDP Connections: $(netstat -anu|awk 'END {print NR-2}')"

OR I like to do things where we're getting multiple numbers from the same output, in more of a snapshot form since the numbers CAN change from one moment to the next. Something like this may be more appropriate, depending on the ultimate goal of your script:

NETSTAT=$(netstat -an)
echo "TCP: $(echo "$NETSTAT"|grep -c ^tcp)"
echo "UDP: $(echo "$NETSTAT"|grep -c ^udp)"
rch1231 commented: The awk and grep examples were great and I had never used the output to a variable like that. Well written. +2
JeoSaurus 32 Posting Whiz in Training

If you just want TCP info from netstat, you can do netstat -at , or netstat -au for UDP.

You can also get some good information from lsof -i A little late, but I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Hello gian!

There are lots of ways to do what you're looking for. Perhaps the simplest way, when the pattern you need to replace is so consistent, is to use the 'sed' command.

In your script you could replace that part of the filename with something like this:

echo SOBA11009_1_1.xml |sed 's/SOBA11009/978-0-387-98595-4/'

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Great! There should be a group-install for that, or you can just install what you need, starting with "yum install httpd".

Take a look at this article. It explains how to install using the "Web Server" package group, as well as how to just install apache, and build from there:

http://hacktux.com/fedora/apache

JeoSaurus 32 Posting Whiz in Training

Hi!

The Linux Documentation Project is one way to start: http://tldp.org

There's a good introduction to Linux here: http://tldp.org/LDP/intro-linux/html/index.html

There are lots of places to go from there. My best advice is to just install it and find something that you want to do with it. Configuring and maintaining a web server is a good way to touch many aspects of Linux at once.

Good luck!

JeoSaurus 32 Posting Whiz in Training

Hi Starfruit!

It really depends on which distribution you're using. Most modern distributions have a package manager that will easily set up a default apache installation for you with very little (if any) configuration required.

Which Linux distribution are you using?

JeoSaurus 32 Posting Whiz in Training

Hi mirasravi!

I'm not *exactly* sure what you're looking for, but personally I like to use as few commands as possible for something like this. That being said, your curl example seems like the most efficient. I'm not sure about the syntax though. I think it should be something like this:

curl http://www.example.com/content/download_content.php?content_id=[0-150] -o file#1.html

That being said, there are endless ways to do loops in all kinds of scripting...

An exercise that I put to some of my tech support team was to come up with a way to use nested loops to print the words to weebl's badger song in as many different scripting/programming languages as possible :) You can do the same thing with your script here, if you're just looking for a learning tool. Otherwise, I think your curl line is probably the most efficient and straightforward.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Whizkid: I think we might need more context... If I had to guess, "CheckRetStat" is probably a function, defined elsewhere in the script.

verdascofernan: I'm not sure what you mean, but it doesn't appear to be related to this thread, so you might have better luck starting a new thread :)

JeoSaurus 32 Posting Whiz in Training

Is that output from 'who'? It looks more like the 'w' command.

The only problem with the straight sed approach above is that you're going to end up with a lot more commas than you expect. You probably don't want commas in the "WHAT" column between commands and arguments and things.

Try something like this, it should provide a fairly clean result (I love the 'read' command):

# w | awk 'NR>1' | while read USER TTY LOGIN IDLE JCPU PCPU WHAT; do
  echo "$USER,$TTY,$LOGIN,$IDLE,$JCPU,$PCPU,$WHAT";
done

The result should look something like this:

USER,TTY,LOGIN@,IDLE,JCPU,PCPU,WHAT
username,pts/0,07:57,0.00s,0.17s,0.04s,screen -dr
username,pts/1,07:57,3days,3.94s,0.00s,sleep 120
username,pts/3,07:58,0.00s,0.28s,0.01s,w

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

>> Can someone help me understand why "tail -f" it stops writing into myfile.txt

Does the log file get rotated at some point? If so, tail is still referencing the OLD version, even though it's been renamed.

I've done something similar using tail -f, but also running a monitoring script that checks the log file to see if it's been rotated (I check logfile.txt every so often to see if the inode has changed)

If the file gets rotated, the monitor script kills the tail script and re-starts it.

As far as alternatives, I"m sure there is one, but I can't think of one at the moment using bash...

I hope this helps!

-G

JeoSaurus 32 Posting Whiz in Training

I like the stat/diff idea!

Do you need to know what files have changed, or just IF they have changed?

I have a script that monitors a directory for changes, and then rsyncs it with another server, does some logging, etc... if any changes occur. To check for changes I store an 'md5sum' of the output of 'find'.

find /path/to/directory |md5sum

This probably wouldn't work for modification times though, so I think you're probably better off with the stat/diff thing. Here's a way to do it that works if there are spaces in your filenames:

find . | while IFS= read filename; do
  stat -c "%Y %n" "$filename"
done

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

This post is 2 days old, so I hope this helps...

There are some commands that are actually made for this! Try "host" or "nslookup". Your results will be much faster and easier to parse than ping.

-G

JeoSaurus 32 Posting Whiz in Training

"cd .." is good for moving up a directory, but you should also know that you can get ANYWHERE in the filesystem if you know the full path! :)

You can use RELATIVE paths or ABSOLUTE paths.

Relative paths are relative to your current working directory.

Example of relative paths:
cd documents/applications <- from your home directory
cd ..  <- takes you UP one directory (back to 'documents')

Absolute paths are relative to the ROOT (very top of the tree) of the filesystem.

Example of absolute paths:
cd /home/user/documents/applications
cd /home/user/documents

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Howdy Gubbu!

I'm not sure I understand the end result you're looking for in this script. Is the purpose to see how long it takes to create the gzip file, or to compare time stamps between two different gzip files?

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

BTW, wget also takes input from a file, so if you had a list of URLs in a file, you could use 'wget -i'

Check out the wget man page for some of the other options you can use. It has great capabilities for mirroring sites and things, which is what I assume you want to do here. (check out --convert-links too, if you have trouble with links in your local copies!)

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Excellent, glad I could help!

JeoSaurus 32 Posting Whiz in Training

Here's an example of something I'm using to monitor an application log for a specific error. I'll put some generic variables in :)

#!/bin/bash

# Set some variables here
logfile="/path/to/logfile"
pattern="this.is.an.error"
email="user@example.com"

# read each new line as it gets written
# to the log file
tail -fn0 $logfile | while read line ; do

  # check each line against our pattern
  echo "$line" | grep -i "$pattern"

  # if a line matches...
  if [ $? = 0 ]; then

    # send an email!
    echo "Found an error: $line" | mail $email -s ERROR

  fi
done

I hope this helps!

-G

JeoSaurus 32 Posting Whiz in Training

Hi Asin!

I think what Aia meant was that this forum is a great place to go for help with something that you're working on, but it's not the best place to post a set of requirements and say "write me a script!". If you want somebody to do all the work for you, you might be better off posting some place like rentacoder (or does daniweb have a section like that?) :)

If you can show us what you've tried so far (shell scripting, not C ;) ), we might be able to point you in the right direction! You'll probably want to loop through your id.dat file for the ids, and use something like 'awk' or 'grep' to pull them out of your data files.

Should be fairly simple!

-G

JeoSaurus 32 Posting Whiz in Training

Nice issue9!

I'd probably use 'seq' to generate those numbers personally. Something like this: seq 1 254 To generate a list of IPs like in issue's example: for i in $(seq 1 254); do echo "192.168.0.$i"; done You've probably got a solution by now, but I hope this helps somebody!

-G

JeoSaurus 32 Posting Whiz in Training

Hello kenshin, how far have you gotten with this? Anything you can do with grep, you can probably do with awk! For example:

grep -y hello filename
# is equal to:
grep -i hello filename
# which is equal to:
awk '/hello/i' filename

Hope this gets you going in the right direction!

-G

JeoSaurus 32 Posting Whiz in Training

It was probably a permissions issue. Did you create the .ssh directory manually? If you check the system logs, you'll probably find an error about permissions on the .ssh directory (just a guess).

-G

JeoSaurus 32 Posting Whiz in Training

Or do you mean the full path to the bash binary?

$ which bash
/bin/bash
JeoSaurus 32 Posting Whiz in Training

That's cool,

I think the main problem that you're having is that the ports required to connect to samba are filtered. Whether it's at your ISP, your router, or the machine itself. Perhaps you've to iptables running and/or samba only configured to allow connecitons from the local network?

Your first nmap was to localhost? What happens if you do it from another box on the network? Try dropping iptables (/etc/init.d/iptables stop)

JeoSaurus 32 Posting Whiz in Training

Hi Darkflib!

I can't speak for the OP, but one of the advantages of running Linux from a usb stick (pen drive, thumb drive, I never know what to call those things...) is that you can configure it to automatically write changes to a "persistence" file, so that if you install new software, or make any other changes, they will still be there after you reboot.

You CAN do this with a CD based live distro, but it usually requires a manual step every time you boot. Also, less power consumption than a CDROM, and you don't have to wait for the cd to spin up every time you access something that's not already cached.

JeoSaurus 32 Posting Whiz in Training

Hi!

It's most likely filtered by your ISP. They generally do this to help prevent old, unpatched Windows machines that are directly connected to the internet from being cracked. In general, this isn't a great idea.

If you absolutely have to access these files over the internet, I'd recommend using VPN to connect to the local network, and you should be able to access the files from there with no problem. You also might want to look into using something more secure, like sftp or something instead of samba for sharing files over the internet.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hi!

That sounds interesting, but I think we're a little unclear about the details. You mention...

"create a menu which will add users doing this in Bash"

...and...

"then adding a list of users again using bash"

Do you mean that the script should be able to present a menu to add users, as well as have the ability to work from a list of users?

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

Hmm... Is that the whole script? I'm not seeing the "users" function called anywhere, or even a terminating "}" for the function :)

-G

JeoSaurus 32 Posting Whiz in Training

That's really odd... It works OK on my system:

$ sed -f DBACheck.sql.sed DBACheck.sql
select granted_role from sys.dba_role_privs where grantee='SYSTEM';

What version of sed are you using? ( sed --version )

-G

JeoSaurus 32 Posting Whiz in Training

Hi!

I hope you've already found an answer to this, but if not, this thread might help:

http://www.linuxquestions.org/questions/linux-networking-3/dns-rndc-service-errror-229950/

JeoSaurus 32 Posting Whiz in Training

Debian is the ORIGINAL "picnic in the park"!!! Apt is the greatest invention ever!

Okay, but seriously. If you want to stick with Debian, which I support completely, look into ndiswrapper. Typically, the hard part of getting a wireless adapter to work in Linux is getting the right driver installed. Some of them are open source, and are therefore supported out of the box, but many of the more popular chipsets are still not "free".

Check to see what chipset your card uses with "lspci". You might be able to grep it out like this:

lspci | grep -i net

That might narrow down the search for a driver. ndiswrapper is a tool that uses the Windows version of the driver. There's another tool called fwcutter that helps to extract those drivers from the Windows installers.

-G

JeoSaurus 32 Posting Whiz in Training

Check out tinycore! (http://www.tinycorelinux.com/)
Or P.U.D. Linux! It's based on Ubuntu.
SLAX also runs great from a pen drive!

For the record, I've run the standard xubuntu on a 2GB stick with no problem, but it was a little cramped for space. I fixed that by setting it up to auto-mount the home directory on my web server if I'm connected to the internet at boot-time.

Like Nic mentioned though, it really depends on what you intend to do with it, what kind of tools you need, how much room you need to store stuff, etc...

-G

JeoSaurus 32 Posting Whiz in Training

Here's a link that might get you started:

http://www.orafaq.com/wiki/SQL*Plus_FAQ#What_is_SQL.2APlus_and_where_does_it_come_from.3F

Experiment with care!

JeoSaurus 32 Posting Whiz in Training

Sure! I don't have any examples in front of me, but the Oracle command line client is sqlplus. There are others, but I think sqlplus is the one that ships with Oracle. You should be able to script something that uses sqlplus to get what you need from the database and then manipulate it with bash.

Can you add 500 to my salary while you're at it?

Thx!
-G

JeoSaurus 32 Posting Whiz in Training

Check out "read"! It will take the user input and do whatever you want with it.

read -p "what is your name?  " name
echo "Nice to meet you $name"

Hope that helps!
-G

JeoSaurus 32 Posting Whiz in Training

Looks like you need to enclose your $line|sed in both cases! Try this:

for line in $(ls *.new); do
  file1="${line}"
  file2="$(echo ${line} | sed 's/\(.*\)..../\1/')"
  diff ${file1} ${file2}
done

Hope it helps!
-G

JeoSaurus 32 Posting Whiz in Training

Heh, for some reason the topic reply notification from this thread reminded me of this, so I had to share:

http://www.gnu.org/fun/jokes/ed.msg.html

-G

JeoSaurus 32 Posting Whiz in Training

Do you use the temporary file for anything in the meantime? I'm biased against temporary files when they can be avoided, personally... Why not stuff it all into a variable and then stuff it into a file when it's done, or just write directly to the destination file? Here's an example of using a variable:

## the quotes are important!
RESULT="$(command --switches)"
echo "$RESULT" > /tmp/finished.txt

Hope that helps!

JeoSaurus 32 Posting Whiz in Training

vim all the way! If it's configured with syntax hilighting and search hilighting, and you can get used to the commands, it's the best ever for command line html/php/any scripting language you can think of.

There are some great quick reference materials out there. This isn't the easiest one to read, but it's one of the most complete:

http://tnerual.eriogerg.free.fr/vimqrc.pdf

The default text editors at the linux command line are usually vi and/or nano (or do they call it pico these days...?) Emacs is also an excellent choice, but it's so huge and clunky in my experience... Nano/pico is probably the easiest to use, but doesn't do syntax hilighting very well.

Hope this helps!

-G

JeoSaurus 32 Posting Whiz in Training

Okay, I needed something to get my mind off work for a few minutes, so here's a quick script I wrote using both of the suggestions above from chris5126 and omrsafetyo. I didn't translate the date, I used the date command to format the date without colons. Here goes, hope it helps!

#!/bin/sh

one=143300
two=143400

while true; do

  time="$(date +%H%M%S)"

  if [ $time -gt $one ] && [ $time -lt $two ]; then
    echo "$time We're in the zone\!"

  elif [ $time -gt $one ] && [ $time -gt $two ]; then
    echo "$time The time has passed"

  elif [ $time -lt $one ] && [ $time -lt $two ]; then
    echo "$time It's not time yet..."
  fi

  sleep 10

done

And here's the output:

$ sh ./timecompare.sh 
143204 It's not time yet...
143214 It's not time yet...
143224 It's not time yet...
143234 It's not time yet...
143244 It's not time yet...
143254 It's not time yet...
143304 We're in the zone\!
143314 We're in the zone\!
143324 We're in the zone\!
143334 We're in the zone\!
143344 We're in the zone\!
143354 We're in the zone\!
143404 The time has passed
143414 The time has passed

Enjoy!

JeoSaurus 32 Posting Whiz in Training

Wow, that's a lot of pipes! I would do it something like this:

awk '{TotCPU += $1}{TotMem += $2}END{print "Total CPU= " TotCPU  "\nTotal Mem= "TotMem}' test.list

Kinda ugly all in one line, but here it is broken down a little:

awk '\
{TotCPU += $1}\
{TotMem += $2}\
END\
{print "Total CPU= " TotCPU  "\nTotal Mem= "TotMem}' test.list

Should output something like:

Total CPU= 5.1
Total Mem= 221.639

Season (format) to taste!

-G

JeoSaurus 32 Posting Whiz in Training

Hi!

The problem is that you're not providing a database name! Try this: mysql -uusername -ppassword database_name ... Hope that helps!
-G

EDIT: And to clarify that error you're getting, since you're surrounding your "-e" with single quotes (' '), and you have single quotes inside the string, it ends your query at the next occurrence of single quotes:

'delete from table where forumid = 25 and replace (title, '

and thinks the next part:

' , ) like %word%'

is supposed to be the database name! Try using regular quotes in one of those instances. Backslashes might be used to escape the occurrence inside the query... not sure though without testing it... :)

-G

JeoSaurus 32 Posting Whiz in Training

I keep a copy of this document posted at every workstation in my office ;)

http://www.digilife.be/quickreferences/QRC/vi%20Quick%20Reference.pdf

Enjoy!
-G

JeoSaurus 32 Posting Whiz in Training

It's just a text file right? What flavor of Unix are you using? You'll probably want to use "vi" or "emacs". If you're not familiar with either of those, you'll probably want to google for some references. Neither of them can really be summed up :)

-G

JeoSaurus 32 Posting Whiz in Training

jbennet, you are a cool dude. I wish you'd come help me convince the IT people I work with... If it ain't broke, don't fix it!

My IT department has a habit of "sniper upgrading" production systems on us... These are the middle of the night upgrades that they don't tell us about because they "shouldn't" affect anything... Nearly lost 3 days of work the last time that happened... But I digress...

Personally, I avoid Fedora like the plague... It's as bleeding-edge as it gets. Ubuntu LTS has been pretty much on par with Debian IMHO for server use, but I am a little scared that they're already using a 2.6.26 kernel in the "stable" release...

JeoSaurus 32 Posting Whiz in Training

One thing to remember about 'sudo su' is that it's not a 'login shell' by default. If you use 'sudo su -l' ('sudo su -' for short) then you'll inherit all of the root user's environment variables, like the path and such.

Just curious though, why would you need to source the install script? If you're only running the one script, you shouldn't need to export any variables to your shell. Especially if you're running it with sudo, because in that environment, you're root just for that installscript, and then you're out and anything that was sourced doesn't matter.

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

Here's a silly question... Have you tried forcing your NIC on the Windows box to run in 'full duplex' mode?

The speed problem is only when going up from the Windows box to the Linux box right? Everything's fine when going from the Windows box to the Linux box?

That sounds like the Windows box may be running at 'half-duplex'. If you check the NIC settings, it's probably set to 'auto-negotiate' or something. Try changing that to full duplex and see if you get different results.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Try using the built in exec command! Also, not sure if that's exactly what you're typing, but you'll need to give "find" a few more arguments... find . -iname *.dat -prune -exec ls -ltr {}\; What this does, bit by bit:

find - the command!

. - the starting point, in this case the cwd

-iname - we want stuff named x, and we dont' care about case (i = insensitive)

*.dat - this is the "x" we were talking about

-exec - execute this command on what we find!

-prune - prune stuff!

ls -ltr - this is the command to execute

{} - this get substited with the find results when the command is run

\; - end of exec statement

I hope this helps!

-G

P.S. I think you need to use "-depth" for prune to do what you want

JeoSaurus 32 Posting Whiz in Training

Hi Shwick!

I'm not exactly sure what you're trying to do with the usermod command there. If it's giving you the usage, then you've likely got a syntax error somewhere. What's the end result you've got in mind here?

On the sudo issue, the "sudo" password is always going to be the password of the user that's running ths sudo command. That's what "sudo" does, it gives a user the ability to run specific commands (or all of them) as a privileged user, using their own login credentials.

If you don't want a user to have sudo access, remove them from the sudoers group. I'm assuming we're talking about Ubuntu here, in which case it's probably the "admin" group. You should be able to tell by checking out the /etc/sudoers file.

Hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Heya Robert72! Did you find what you were looking for, or did you need more specific examples?

-G

JeoSaurus 32 Posting Whiz in Training

I think you're looking for read -p

I have some examples, but running to a meeting... If you still need help, I'll post it later!

-G