Todd A. Jacobs | 5 Jul 2011 02:53
Favicon

Re: Display date between 2 giving date

On Jun 9, 11:49 am, dovito <*... <at> italghanaweb.com> wrote:
> echo  "<pre>";
> print_r($dateMonthYearArr);
> echo "";

You're printing the array directly with print_r, when what you really
want
to do is print each member of the array using a foreach loop.

See http://php.net/manual/en/control-structures.foreach.php for
details,
but this works fine from the command line:

  php -r '$a = array(1, 2, 3); foreach ($a as $value) {print "$value
\n";}'

Hope that helps!

Roger | 19 Jul 2011 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

Todd A. Jacobs | 21 Jul 2011 01:27
Favicon

Re: bash (or other shell) help with usernames

On Jul 19, 3:35 pm, Roger <roger.in.eug...@...> wrote:
> #!/bin/bash
> touch ~$1/FILENAME

This won't work because of the way that bash handles the quoting. You
could use eval:

eval "touch ~${1}/FILENAME"

so that the positional parameter is expanded and then re-processed as
a tilde expansion, but that's rather unsafe. You're better off hard-
coding the path to the home directory like so:

touch /home/${1}/FILENAME

which should be fine unless you have multiple homes for different
users (e.g. if you're using NFS, or have thousands of users and are
splitting home partitions onto different spindles for performance
reasons).

There are also other ways to get the home directory for a user that
don't require tilde expansion. For example, given a username of foo:

set -- foo
getent passwd $1 | cut -d: -f6

You could use that to build the path, which might be useful in the
event that you can't assume that the user's home directory will be
under /home.

(Continue reading)

Roger | 21 Jul 2011 17:03
Picon

Re: Re: bash (or other shell) help with usernames

> There are also other ways to get the home directory for a user that
> don't require tilde expansion. For example, given a username of foo:
>
> set -- foo
> getent passwd $1 | cut -d: -f6
>
> You could use that to build the path, which might be useful in the
> event that you can't assume that the user's home directory will be
> under /home.

I think this will be it.  there are 2 different path possibilities,
one for students, the other for staff.  'touch' was an example, I'm
actually going to be setting permissions on a sub-directory in their
home directory when they connect via SMB or AFP.

--

-- 
Roger


Gmane