JeoSaurus 32 Posting Whiz in Training

It sounds like you already have the Pi, but I got a cubieboard for this purpose because it has an actual SATA port. I've got a 1TB 2.5" drive, powered through the cubieboard (Just make sure your power supply is at least 2amps or better!).

JeoSaurus 32 Posting Whiz in Training

Seems like @rch1231 has what OP is looking for. Here's an alternative that I like, using the 'seq' command as the counter:

#!/bin/bash
while true; do
    for i in $(seq 1 20); do
        wget http://test.com
    done
    sleep 2
done

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

ITPT: Check out R1Soft (Idera Server Backup) or Crashplan. I don't know of any one piece of software that will do backups AND notify you of hardware changes on the client side, but if you want incremental or continuous backups scheduled from a central server, R1Soft is a good choice. It's cross-platform too, so you can use it on Windows or Linux.

JeoSaurus 32 Posting Whiz in Training

Apt is what makes Ubuntu (and Debian) awesome! You should be able to get MySQL running with a single command:

sudo apt-get install mysql-server mysql-client

Unless there's a really good reason (like you need a specific version of mysql that isn't in the Ubuntu repository) I wouldn't install it any other way.

Good luck!

JeoSaurus 32 Posting Whiz in Training

You could also just call the interpreter first. For instance, if we know that "$1" is a shell script:

/bin/sh $1

or

/bin/bash $1

I hope rohan1111 gets back to us about what the problem was. If the script really is essentially (as others have guessed) just:

chmod 744 $1
$1

...then I think you are all on the right track.

JeoSaurus 32 Posting Whiz in Training

Most options for .bash_profile that are cross-platform compatible, though you may need to script something to detect paths for different OS's. What kind of profile options are you looking for?

As far as OS detection, here's a link that should get you started: Click Here

I hope this helps!
-Jeo

JeoSaurus 32 Posting Whiz in Training

Siberian, do you still need help with this? What exactly are you trying to find out?

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

Hi!
Do you have the 'bc' command, or 'printf' available in your shell? You should be able to convert values to and from different formats with one of those. All the information you need should be in the man pages, but let us know if you need examples.

JeoSaurus 32 Posting Whiz in Training

If you want to get data from a web page and do something with it, there are lots of good options.

Depending on what you want to do, one of my favorites is wget. Here's an example:

wget -qO- ipchicken.com

This gets you the raw html from ipchicken.com. You can easily parse this if you know what you're looking for, like say for instance you just want to get your IP address:

wget -qO- ipchicken.com|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'

Now if you want to get output that is a little more human readable, you might look into using 'lynx' or 'elinks' with their 'dump' options, which will give you formatted text, without the html tags.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

If you DO mean 'pylunch', you might want to start with their official documentation:
http://pylunch.googlecode.com/files/PyLunch-0.2.pdf

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Great, thanks for the follow-up! Glad you got it figured out :)

JeoSaurus 32 Posting Whiz in Training

Oh! vzfs! Is this an OpenVZ or Virtuozzo virtual machine? If so, you may have a quota issue. Check out this thread: http://forum.openvz.org/index.php?t=msg&goto=35897&

The OP in that thread had a HUGE discrepancy between du and df output. The thread links to an article in the OpenVZ wiki which is pretty technical, but I think that's where the answer lies. If you are the administrator for the hardware node, you might want to check on the quota for the container. If not, you might want to check with your host and see if there's anything they can do to fix it.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Right! There's nothing wrong with it, I just have a personal bias against pipes ;)

JeoSaurus 32 Posting Whiz in Training

CimmerianX, are you some kind of masochist? That sounds like fun though! I'll bet you could get openvz running somewhere in there too.

dihmen, I assume you are interested in using the built-in "KVM" (Kernel Virtual Machine) functionality in CentOS/RHEL 6. Here's a guide to setting up and running KVM under RHEL 6 (or CentOS 6): http://itscblog.tamu.edu/startup-guide-for-kvm-on-centos-6/

Another option that is built into the kernel is LXC (LinuX Containers). It's not full virtualization like KVM, but it's nice and lightweight. It's similar to OpenVZ if you have any experience with that. Here's a link: http://wiki.centos.org/HowTos/LXC-on-CentOS6

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

SPeed_FANat1c,

That's interesting! I'm stumped... Can we see the full 'df' output?

JeoSaurus 32 Posting Whiz in Training

rubberman,

That's one of the first things I thought about (I used to work for a company that writes backup software and this came up a lot) so I researched it to refresh my memory. The filesystem (ext2, ext3, ext4) reserves about 5% for a buffer zone by default, which is nowhere near the 20ish percent that our OP is seeing.

This does come up a lot on larger filesystems. Since the default is 5%, you lose about 50GB on a 1TB partition, or 400GB on an 8TB partition. But 5% of 20GB is only 1GB. You usually notice the difference in the space remaining in your 'df' output, but 'du' output should be correct. I suspect that whats being reported is actually correct, but we aren't seeing all the numbers.

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

I like to use 'tee' to print the results to the console AND to a file. Also, the "--color=auto" option to grep can help with readability of output, but I'm not sure how well it works in all shells when reading the results from a text file. Try something like this:

grep --color=auto "pattern" /path/to/file.txt | tee -a logfile.txt

I like the idea of using sed to double-space, but you can accomplish the same thing (grep + sed G) in one line of awk:

awk '/pattern/ {print $0 "\n"}' /path/to/file.txt

I hope this helps!
-G

LaxLoafer commented: Well done Gromit :-) +3
JeoSaurus 32 Posting Whiz in Training

Hi!

Try using the date command to generate the date for the filename. Something like this should work:

zip -r forum_backup_$(date +%Y%m%d) ~/public_html/forum/*

I took some liberty with the date format there. If you put the date first, then the month and day, it sorts nicely. You can re-arrange them if you want.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hello Moe2!

You may want to look into using pam_passwdqc.so. If configured correctly, it should tell the user what's acceptable when the passwd command is invoked.

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Hidden files should be included in du output. I'm not familiar with ncdu, but I'm checking it out now!
What do you get from this command: sudo du -sh /

Thanks!
-G

JeoSaurus 32 Posting Whiz in Training

I'm not completely sure, but I don't think you can use TLS over netcat. You'll need something to handle the SSL/TLS connection. It looks like you can do this with something like 'gnutls-cli' or even the 'openssl' client. This might be what you're looking for:

example using openssl
example using gnutls-cli

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Regex!
Try something like this:

var='96.33% from 120'
decimal=$(echo $var|grep -Eo '[0-9]*\.[0-9]*')
echo $decimal

I hope this helps!
-G

JeoSaurus 32 Posting Whiz in Training

Neat! Do you want the date to be updated each time? In your code snippet, you run the 'date' command one time, so each entry will be the same date/time. Try something like this!

#!/bin/sh
for i in $(seq 1 600); do
    date |tee -a outputfile
    sleep 1
done

Or if you're using bash:

#!/bin/bash
for i in {1..600}; do
    date |tee -a outputfile
    sleep 1
done

That should give you the results you need, and print them to the console at the same time it's writing to the output file. If you don't need the date to be current for each iteration, you can just set your date variable first, like in your example:

#!/bin/bash
dt=$(date)
for i in {1..600}; do
    echo $dt |tee -a outputfile
    sleep 1
done

I hope this helps!

Baduizm commented: Yeah +0
JeoSaurus 32 Posting Whiz in Training

Hi MCLASS80!

Have you got any sample data for us? What are you using to get the dump? Could we see that part of your existing script?

From there, we should be able to help you figure out how to trim out the unwanted stuff.

Thanks!

JeoSaurus 32 Posting Whiz in Training

Hello Rbezona!

I think it might help if we could see the script that was used. I can't think of anything specific to ksh that would cause that behavior, but I'm wondering if perhaps each iteration was starting over from the beginning with a longer list of files...

For instance first run processes file1, second run processes file1 AND file2 (instead of just file2) etc...

JeoSaurus 32 Posting Whiz in Training

Cut works well for that! Or awk:

echo $file | awk -F/ '{print $3}'

You could also do something with sed...

echo $file | sed -n 's%/media/\([^/]*\)/.*%\1%p'

HTH!
-G

JeoSaurus 32 Posting Whiz in Training

I wonder if adding the '-v' flag to your mv command would give you what you're looking for?

Example:
find /media/D_Drive/Music/ -name '&.*' -exec sh -c 'mv -v "$0" "${0%//\&/and}"' {} \;

Aside from that, I think what I would end up doing is just using find to get the file list, and writing a bash script to iterate through the list, 'echo'ing each command as it goes.

JeoSaurus 32 Posting Whiz in Training

Okay, because dangling threads make me crazy when I'm personally searching for something, here's a simple loop that will output the greatest number:

#!/bin/bash
echo Input some numbers, separated by a space please:
read -a choice

# Set "greatest" to the first number
# in the list
greatest=${choice[0]}

for num in ${choice[@]}; do

    # This will compare each number to the previous
    # "greatest" number, and set the "greatest" var
    if [ $num -gt $greatest ]; then
        greatest=$num
    fi

done

# After the loop runs out of numbers, print the "greatest"
echo "The greatest number is: $greatest"

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

TL;DR version:

try awk -F/ '{print $5 "-" $6}' Albums-linux.txt "$5" and "$6" might need to be tweaked depending on your path.

Now for the full explanation:

Are you asking how to integrate this into your example? My example was just to illustrate how the substitution works, and what syntax the shell expects.

You would simply replace this:

${"${line:21}"///-}

with this:

${line/\//-}

So it would look more like this:

while read line; do echo "${line/\//-}"; done < Albums-linux.txt

If you have to start the line at position:21, then you might not be able to do it all in one operation using this method. If that's the case, you will want to use something different like sed or awk. Is it safe to assume that Albums-linux.txt contains a list of full paths, and the data that you want starts at :21? You might be able to do something like this, for example, instead:

line="/home/user/audio/GroupName/albumName"; echo $line |awk -F/ '{print $5 "-" $6}'

In this example, we set the field separator in awk to the "/" character. The first field is empty (before the first slash), so if we count the fields in my example, you get GroupName at $5 and albumName at $6. The print statement prints fields 5 and 6 with a hyphen in between, so the result is this:

GroupName-albumName

Which would translate in your original example to something like this self-contained one line awk script:

awk -F/ '{print $5 "-" $6}' Albums-linux.txt
JeoSaurus 32 Posting Whiz in Training

Show us what you've tried, and we might be able to help you figure out how to make it work! :)

JeoSaurus 32 Posting Whiz in Training

Hello dwlamb!

Without your exact example data it's hard to tell for sure, but I believe that bash expects the first parameter to be a variable, which means you can leave out the '$'. This simplified example seems to work for me, and might give you a better idea of how the substitution should look:

line="GroupName/albumName"
echo "$line"
echo "${line/\//-}"

The result:

GroupName/albumName
GroupName-albumName

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Hi Sundown G!

It looks like you've got the sum down pretty well. What have you tried for the max number, average and multiplication options?
Multiplication should be fairly similar to what you're doing with the sum here (try something simple like sum=$((sum*choice[a])), but make sure you set sum=1 before the beginning of the 'for' loop)

Once you have that, average should be easy.

Max number will be a slightly different operation. Just call the first number "high", compare each number to the previous "high", and overwrite "high" if it's greater.

JeoSaurus 32 Posting Whiz in Training

Sorry, I meant to path to each individual file. You can't get a directory listing unless the web server allows it.

JeoSaurus 32 Posting Whiz in Training

Not "corrected"! Enhanced! :)

You CAN create an init script and drop it into /etc/init.d
But if it's just a script that you want to run once, at boot time, /etc/rc.local is the super-simple way to do it.

I suspect the OP might have issues with this though, if he doesn't have root privileges...

dinesh17: Do you have 'root' or 'sudo' access on the system in question? You mention having trouble running the script manually. You *should* be able to run it from the command line as root, or with 'sudo'.

JeoSaurus 32 Posting Whiz in Training

/etc/rc.local is a good place to put simple scripts that you want executed at boot-time. Lines in rc.local are executed as root (unless specified otherwise) and after all the other startup scripts have run.

JeoSaurus 32 Posting Whiz in Training

I see. In that case, you'll probably need to check each file individually. There's no way to discover files/directories on a web server unless they're linked from an index page, or you know the full path already.

JeoSaurus 32 Posting Whiz in Training

Well cgrep is just the sed script in the example link. You might even be able to use it as-is (I haven't actually looked at it yet)

JeoSaurus 32 Posting Whiz in Training

Hi!

That's not a problem, as long as your web server allows directory listing (Options Indexes), and there is no 'index' file there. OR, alternately, if this is a web server that is under your control you could CREATE an index page that lists the files your concerned about.

Otherwise, if there is no way to get the directory list, say, in a web browser, then you're not going to be able to get it with any of the tools that I've listed either.

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Oh, right! Not all versions of grep have the -A and -B flags. Here's a definition:

-A NUM, --after-context=NUM
      Print  NUM  lines of trailing context after matching lines.  Places a line containing -- between con-
      tiguous groups of matches.

-B NUM, --before-context=NUM
      Print NUM lines of leading context before matching lines.  Places a line containing --  between  con-
      tiguous groups of matches.

There's a way to do this with sed, but I haven't sat down with it to break it down and understand it myself. Here's a link to the O'reilly Unix Power Tools page that talks about it: http://docstore.mik.ua/orelly/unix3/upt/ch13_09.htm

And here's a link to the 'cgrep' script that they use in the example: http://examples.oreilly.com/9780596003302/example_files.tar.gz

I hope this helps!

4evrmrepylrning commented: Much appreciated! +1
JeoSaurus 32 Posting Whiz in Training

Glad to hear that it helped!

For something like that (keeping a variable consistent between runs of the script), you might want to use a temporary file, and ask at the beginning of the script if the user wants to use information from the previous session.

JeoSaurus 32 Posting Whiz in Training

Hmm... Are you using an editor that supports syntax highlighting?

This error:
unexpected EOF while looking for matching `"'

...means that there's something left open somewhere. That could mean that there's an extra quotation mark somewhere, or a missing one. In THIS case, you've left a set of brackets open:

echo "${Tasksarray[${Tasksarraylength}]"
       ^Open bracket                   ^Missing bracket
JeoSaurus 32 Posting Whiz in Training

Easy!

If you want to check individual files, take a look at "wget --spider" or "curl -I"

(Just in case you don't already know, you can get a list of options for most commands with the 'man' command. Example: man curl )

Here's an example using curl to see if the google logo exists:

## Example where the file exists
# curl -I http://www.google.com/images/srpr/logo3w.png
HTTP/1.1 200 OK
Content-Type: image/png
Content-Length: 7007
Last-Modified: Fri, 05 Aug 2011 02:40:26 GMT
Date: Sat, 10 Mar 2012 17:41:50 GMT
Expires: Sat, 10 Mar 2012 17:41:50 GMT
Cache-Control: private, max-age=31536000
X-Content-Type-Options: nosniff
Server: sffe
X-XSS-Protection: 1; mode=block

## Example where the file does NOT exist
# curl -I http://www.google.com/images/srpr/logo3wx.png
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Sat, 10 Mar 2012 17:46:56 GMT
Server: sffe
Content-Length: 954
X-XSS-Protection: 1; mode=block

It gives you the type of file, modification times, etc. without actually downloading the file.

Here's a wget example. The output is much simpler. It just tells you if it exists:

## File exists (200 OK)
# wget -nv --spider http://www.google.com/images/srpr/logo3w.png
2012-03-10 11:45:44 URL: http://www.google.com/images/srpr/logo3w.png 200 OK

## File does NOT exist
# wget -nv --spider http://www.google.com/images/srpr/logo3wx.png
http://www.google.com/images/srpr/logo3wx.png:
Remote file does not exist -- broken link!!!

If you want to read the contents of an entire directory, you can do that only if that directory allows 'directory listing'. If you can browse to that directory …

JeoSaurus 32 Posting Whiz in Training

Glad we could help!

Using $() is only needed if there is a command you need to execute, like where you are calling the 'date' command.

To just set a variable, you don't need $(). Line 27 should *probably* be more like: MondayTask1=$Whattask

JeoSaurus 32 Posting Whiz in Training

If you are pasting into vi, you might try running ":set paste" in vi before hitting insert and pasting.

JeoSaurus 32 Posting Whiz in Training

I wonder what the solution was? :)
I haven't used cygwin in a while. I'm curious to know what the problem was!

JeoSaurus 32 Posting Whiz in Training

Hi nakresimin!

What kind of database? MySQL has a command line utility that allows you to execute database commands from a shell script. For instance, to delete all the rows in a table called bartable, in a database called dbfoo:

mysql dbfoo -e 'delete from bartable'

Of course, you'll need to have a .my.cnf file with login credentials for that database OR provide the username and password to the mysql command (mysql -uuser -ppass dbfoo ...).

That's all I've got!

JeoSaurus 32 Posting Whiz in Training

That's a good question! I don't think your sed line is going to work, unless each record is all on one line. The way the records appear to be formatted, your sort|uniq would give you a big pile of nothing.

Here's a (kind of ugly) script that I wrote to to see if this would work... I *think* it does what you're looking for.

input="test.txt"
nums="$(grep '^<num>' $input |sort -u)"
for num in $nums; do
    grep -B6 -A3 $num $input|head -n 9
    echo
done

In this case, 'test.txt' is my input file, containing the 4 sample records you provided. Here's my output:

# sh test.sh
<record>
<dateadd>012012</dateadd>
<nid>R04607295</nid>
<reflink></reflink>
<FPI>YES</FPI><TPG>NO</TPG><FT>YES</FT>
<num>631</num>
<author>Anon</author>
<title>ON THE WED</title>
</record>

<record>
<dateadd>012012</dateadd>
<idref>R04607297</idref>
<reflink></reflink>
<type>Article</type>
<FPI>YES</FPI><TPG>NO</TPG><FT>YES</FT>
<num>651</num>
<author>Bent, E</author>
<title>ENTRANCES AND EXITS</title>

I hope this helps, or at least gives you a place to start! There's probably a much cleaner way to do it, but this was quick and simple.

JeoSaurus 32 Posting Whiz in Training

Hello Srikanth!

This should be pretty easy in csh, depending on what utilities you have installed. Do you have 'wget', 'netcat' (nc) or 'curl' available in the shell?

JeoSaurus 32 Posting Whiz in Training

Hello Felipevd!

The problem is actually pretty simple. When doing an 'if' comparison, you want to use square brackets [] instead of parens:

...
if [ $Day="Monday" ]; then
...

I noticed some other issues that you'll probably see after the if statement is 'fixed'.

When you want to execute code in the context of setting a variable, you will need to put it in either:

`backticks`
(the little mark that usually shares the ~tilde key)

OR this notation with the dollar sign and parentheses:

$(some commands here)

I prefer the second method. So for example, your "Monday=date +%d" should be:

...
Monday=$(date +%d)
...

I hope this helps!

JeoSaurus 32 Posting Whiz in Training

Hello Vikram! I'm sorry you've gone so long without a reply.

The last time I used Solaris, most of my scripting was done with plain ol' bourne shell and bash scripting.

I've always found the advanced bash scripting guide at the linux documentation project to be a good reference, and it might even be a good starting point.

I hope this helps!
-Joe