Skip to content

u/toebox

In this archive from Jul 2011 to Dec 2014

0
posts
81
comments
0
media
218
score

I'm not sure if this is what I was looking for, but I piped the grep output to a text file, put #!/bin/bash at the top, and ran it like a regular script. if anyone has a solution that doesn't involve creating an executable script as a file as a go between, that'd be great.

grep "wget" README | bash

Accomplishes the same thing.

Adding '#!/bin/bash' or '#!/usr/bin/perl' to the top of a file only matters if you are invoking a script like './script.sh' or './script.pl', because Linux doesn't use the file extension like windows does, it uses the special hashbang comment at the top to decide what to run the script with.

Alternatively, you can invoke a script directly with the interpreter you wish, such as 'bash script.sh' or 'perl script.pl'. This way does not require the hashbang comment (the script doesn't even need to be executable!).

Another way you could write 'bash script.sh' is 'bash < script.sh', bash will read script.sh from STDIN and happily execute each line. 'cat script.sh | bash' works the same way, and the above 'grep "wget" README | bash' works as well.

1 points

NFS can be used with PXE and TFTP for net booting.

But in this case you'll just put all of your WWW files (/srv/www or whatever) on a single server, then mount that using NFS on each of the 3 webservers (to /var/www), so any change made to those files on any web server will actually happen on the NFS server, and the other web servers will get it instantly.

Configuring Apache with NFS

3 points

A shared file-server (NFS, for example) is pretty common. If you have any databases you'd have to replicate them or host them on the file-server as well.

If your webapps are session-aware, you need to store them somewhere shared as well (NFS, DB, Memcached, etc).

If that's too much overhead, you can just remember to rsync the files when you change something (or set a sync in cron), and use 'session persistence' in your LB to always route a user's IP to the same server (unless it goes down).

2 points

It may be worth running apache with vhosts (all subdomains) on all but one server, and use the extra server as a low-level loadbalancer (LVS, piranha, keepalived, ldirectord, etc). That will balance the loads between all servers evenly and provide redundancy if one server goes down. This puts very little load on the public facing server and you should easily be able to move 100Mbps through the Pi if needed (you'll get even more performance out of a 'directly routed' configuration, where all return traffic comes from the 'real' servers).

Otherwise, you can use a layer-7 (application aware) load balancer like HAProxy, Apache (mod proxy), nginx, etc to route the packets to the correct server based on the 'host:' header in the request. If you're doing any SSL you'll have to move that up front for this solution to work.

3 points

http://www.keepalived.org/
http://haproxy.1wt.eu/

There's no reason to partition websites to single servers when they can run at the same time on multiple servers, you can distribute load evenly between them and even take them down one at a time for upgrades and testing.

Use a single database/nfs server to pull data from (although most dbs can be replicated between 2 active hosts while keeping the performance, filesystems are trickier).

Session based applications can be set as persistant (a user will always go to the same server, unless it has gone down) or you can implement sessions in something like memcached and share those among your pool of www servers.

Something like this.

2 points

There's a difference between talking about "a square root" and sqrt(x) or √x, the latter two are mathematical functions which can only have one output. By convention, the √ function is defined as the principle (positive) square root.

If you want both values, you have to specify ±√:

f(x) = ±√x is not a function in the proper sense, but a multi-valued function: it assigns to each positive real number x two values: the (positive) square root of x (√x), and -√x.

As for why (0,inf) was chosen as the domain, it just makes things neater (same reason pi isn't 2*pi):

Consider the very simple rule √(ab) = √(a) * √(b), that wouldn't work if the function returned a negative, and it's FUBAR if each of the 3 instances could be either positive or negative!

9 points

If your ids are Primary keys (or at least unique indexes), you can use 'INSERT IGNORE' to insert only rows with different ids without aborting or duplicating anything.

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.

IGNORE has a similar effect on inserts into partitioned tables where no partition matching a given value is found. Without IGNORE, such INSERT statements are aborted with an error; however, when INSERT IGNORE is used, the insert operation fails silently for the row containing the unmatched value, but any rows that are matched are inserted. For an example, see Section 18.2.2, “LIST Partitioning”.

Data conversions that would trigger errors abort the statement if IGNORE is not specified. With IGNORE, invalid values are adjusted to the closest values and inserted; warnings are produced but the statement does not abort. You can determine with the mysql_info() C API function how many rows were actually inserted into the table.

There's also "INSERT ... ON DUPLICATE KEY UPDATE" if you need to do fancier stuff.

1 points

The only way I can think of is to open an xforwarding session (ssh -X), then pipe something to "xsel --clipboard" to copy it, then redirect xsel (linux), pbpaste (osx), or getclip (cygwin) to a file on your local machine.. I'm not sure how well it works with large or binary files, though.

3 points

Postfix is very simple, if you can set an outbound server on your device, literally all you have to do is add the device's IP address to mynetworks (/etc/main.cf) and it will act as a relay for that device with no other configuration... You can disable local delivery like this (optional, but probably wise).

if you need to send to a certain address and have it forward to gmail (device@sends.here -> forward@gmail.com) you can use /etc/aliases or set up a simple rewrite. The postfix documentation is some of the best I've ever seen, read it (basic, relay and/or alias and/or rewriting)!

If you want to further lock things down, you could also simply have an iptables rule that blocks port 25 from any IP except your device, postfix wouldn't allow others to send anyway (unless you fat-fingered some config), but that could reduce rejects building up in your logs.

Sendmail is similar but slightly more complicated IIRC.

3 points

You shouldn't use the ! on the terminal either. If you run !foo, bash will search its recent history for commands beginning with 'foo' and execute the most recent.

So running '!/home/user/.teamspeak/TeamSpeak3-Client-linux_x86/ts3client_runscript.sh' will search the bash history for '/home/user/.teamspeak/TeamSpeak3-Client-linux_x86/ts3client_runscript.sh' and run the most recent command matching.. I'm not sure that's what you intended (although it may appear to work if you've run the command without the ! before and it's still in your history).

2 points

So it is mounted and if you copy whatever files you may need to a folder on your local computer (as root) you should be able to change permissions from there.. Grab what you need first (most of your files should be under /media/Macintosh HD/User).

Then, to kill the GUID stuff, first unmount it with umount, then:

dd if=/dev/zero of=/dev/sdc bs=1M count=1

You'll then have a drive you can freely partition/format (I'm assuming there are GUI tools for it, but I always just use fdisk/parted and mkfs). You may need to unplug/replug the USB before you can do anything with it.

EDIT: 'bs=1M' may actually be 'bs=1m', BSD and GNU are different and I always forget which is which.

2 points

OSX drives have a weird partition table your computer might not understand. If you know the /dev/ path to the drive, you can write zeros to the first few sectors, then it should show up as an empty drive and you'll be able to format it.

Be VERY careful with this command, if you run it on any device except the HDD in question, it's MBT/Partition table will be gone forever:

dd if=/dev/zero of=/dev/<DEVICE_ID> bs=1M count=1

Make sure to change <DEVICE_ID> to the correct path to that device.

4 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.