Roger | 19 Jul 21:35
Picon

bash (or other shell) help with usernames

Trying to do something simple, but it's not working.
Just trying to pass an argument (in this case a username), and have it
touch a file in that user's directory.
calling the script like this:
SCRIPTNAME  USERNAME

#!/bin/bash
touch ~$1/FILENAME

Does not work.  I get no such directory or file.  If I hard code in:
touch  ~USERNAME/FILENAME

Then it works.
If I call it with:
SCRIPTNAME   ~USERNAME    (Note the ~)

There must be something going on with passing in the username via the
command prompt and using that string with tilde expansion.

I'm trying to do something when a user connects to an SMB share on
linux.  I can retrieve the username via $U in the pre-exec area.  I
could add the full path in SMB.conf, but not all users are in the same
path for their home directories.   Using the tilde with their username
is best.

--

-- 
Roger

dovito | 9 Jun 17:49

Display date between 2 giving date

I have a problem with a PHP script to output date format according to
two dates. $fromDate and $toDate.
Let say if the date between is 6 i wanted to display  day 1 , day 2 ,
day3 .....day6.
I have a script that follows

 <?php
$fromDate = "07/20/2011"; // month / day / year
$toDate = "07/22/2011";  // month / day / year

$dateMonthYearArr = array();
$fromDateSTR = strtotime($fromDate);
$toDateSTR = strtotime($toDate);

for ($currentDateSTR = $fromDateSTR;
$currentDateSTR <= $toDateSTR;
$currentDateSTR += (60 * 60 * 24)) {
// use date() and $currentDateSTR to format the dates in between
$currentDateStr = date("Y-m-d",$currentDateSTR);
$dateMonthYearArr[] = $currentDateStr;
//print $currentDateStr."<br />";
}

echo  "<pre>";
print_r($dateMonthYearArr);
echo "";

?>

the output is:
(Continue reading)

dovito | 5 Jun 04:21

Php image renaming

I have a script for image upload and rename. Anytime I try to rename a
image with a name contaning an apostrophe I get something wrong. For
Exemple if I want to rename a image from "dream" to "dream's"  I get
an error. Can someone help? Thank you!

Todd A. Jacobs | 10 Apr 13:26
Favicon

Network redirection in bash

I'm trying something a little weird, and am not having much success
with my shell redirection to a network port. I'm trying to send an MS
Word file to antiword running out of inetd. Here's what I have on the
client side:

    exec 4<> /dev/tcp/127.0.0.1/2100
    cat /tmp/foo.doc >&4
    cat <&4

This seems like it should work, but I never get any results back from
antiword. Basically, it just waits until the service times out.

I'm hoping I'm just doing something wrong with my shell redirection
here. Thoughts?

Todd A. Jacobs | 3 Apr 01:38
Favicon

Easier way to toggle comments?

I'm using the following to toggle lines on and off in my Ruby .gemrc
file:

    toggle-rdoc () {
        local FILE="$HOME/.gemrc"
        { rm $FILE &&
          awk '/^#/ {sub(/^#/, "", $0); print; next};
                  /^[^#]/ {sub(/^/, "#", $0); print}' > $FILE
        } < $FILE
        cat $FILE
    }

It works, but it just seems like there ought to be an easier way. I
couldn't get it to work with sed for some reason; it seems to need
some serious branching to work at all in sed. Here's what I tried in
sed:

    alias toggle-rdoc='sed -ri "/^#/{ s/^#// }; s/^([^#])/#\1/"
~/.gemrc; cat ~/.gemrc'

but the results are always the same; no toggling happens at all.
*sigh*

Can anyone think of a more elegant solution for this problem?

Todd A. Jacobs | 27 Mar 00:31
Favicon

tcltest?

Does anyone here know anything about tcltest? I ran across a reference
to it today while trying to find some resources for TDD in tcl/tk. Not
sure if it's suitable, so I thought I'd ask for opinions.

Recommended links for TDD with tcl/tk, anyone?

Todd A. Jacobs | 24 Mar 12:06
Picon

Script or one-liner for bumping revision numbers?

I was noodling around today about ways to bump an arbitrarily-deep
revision number. By that, I mean a good perl (or whatever) one-liner
that doesn't care if the revision number is 7, 1.1, or 2.3.4, and can
just bump up the last digit in the sequence and write it back in-
place.

I have a complicated shell snippet that sort of works, but it's ugly
and inefficient. Anyone know of a reliable way to do this?

Todd A. Jacobs | 24 Mar 12:03
Picon

New script up on GitHub: stackmount.sh

In addition to learning about scripting, this groups is also for
sharing cool scripts and one-liners that others might find helpful.
Here's my contribution for the day:

    https://github.com/CodeGnome/stackmount.sh

Synopsis: Stack encfs on top of sshfs, in order to mount a remote
encrypted directory. This enables remote storage of sensitive data on
hosts which may not be fully secure, e.g. on a virtual private server.

As always, patches and suggestions for improvement are welcome. :)

Todd A. Jacobs | 21 Mar 22:15
Picon

Challenges?

Does anyone on the list have any current shell or ruby challenges that
they're dealing with? Things have been very quiet here lately, and I'm
looking for something a little tricky to stretch the grey matter.

Todd A. Jacobs | 15 Mar 01:29
Picon

Calling a list of methods in Ruby

I have some code with an array of method names, and I want to call
each method in turn. Right now, I have:

    [ :foo, :bar, :baz ].each { |the_method|
some_object.method(the_method).call }

which works. However, the whole method(x).call chain seems like the
long way around this particular issue. AFAICT, Ruby doesn't really
support indirect variables like bash does (e.g. the ${!foo} construct)
so I'm not sure how to do this in a less bizarre way.

Anyone know the Ruby Way to do this?

Todd A. Jacobs | 13 Mar 06:39
Picon

New script: heroku-backups.sh

#!/bin/bash
#
# Name:
#     heroku-backups.sh
#
# Purpose:
#     Backup a PostgreSQL database from Heroku using the heroku gem.
#
# Author:
#     Todd A. Jacobs <bash_junkie@...>
#
# Versioning:
#     $Revision: 1.4 $
#     $Date: 2011/03/13 05:38:19 $

set -e
set -o pipefail

# Modify the default paths here. These values can be overridden from
the
# environment at runtime.
: ${RVM_SETUP_SCRIPT:="/path/to/rvm"}
: ${PROJECT_DIR="/path/to/project"}
: ${BACKUP_DIR="/path/to/backups"}

# Capture date at start of run, to avoid having the wrong date for
# long-running jobs that start near midnight.
DATE=$(date +%F-%s.%N)

# If heroku gem isn't in the path, try using rvm.
(Continue reading)


Gmane