Re: advanced scripting problems - or wrong approach?

2024-06-03 Thread David Christensen

On 6/2/24 21:35, DdB wrote:

Am 02.06.2024 um 02:41 schrieb DdB:

Will share my findings, once i made more progress...


Here is what i've got before utilizing it:



datakanja@PBuster-NFox:/mnt/tmp$ cat test
#!/bin/bash -e
# testing usefulness of coprocess to control host and backup machine from a 
single script.
# beware: do not use subprocesses or pipes, as that will confuse the pipes 
setup by coproc!
# At this point, this interface may not be very flexible
# but trying to follow best practices for using coproc in bash scripts
# todo (deferred): how to handle stderr inside coproc?
# todo (deferred): what, if coproc dies unexpectedly?

# setting up the coprocess:
stdout_to_ssh_stdin=5 # arbitrary choice outside the range of used file 
desciptors
stdin_from_ssh_stdout=6

coproc SSH { bash; } # for testing purposes, i refrain from really 
involving ssh just yet and replace it with bash:

# save filedescriptors by duplicating them:
eval "exec ${stdin_from_ssh_stdout}<&${SSH[0]} 
${stdout_to_ssh_stdin}>&${SSH[1]}"
echo The PID of the coproc is: $SSH_PID # possibly useful for inspection

unique_eof_delimirer=""
line=""
# collect the output available and print it locally (synchonous):
function print-immediate-output () {
while IFS= read -r -u "${stdin_from_ssh_stdout}" line
do
if [[ "${line:0-5:5}" == "$unique_eof_delimirer" ]] # currently, 
the length is fixed
then
line="${line%}"
if [[ ! -z $line ]]
then
printf '%s\n' "$line"
fi
break
fi
printf '%s\n' "$line"
done
}

# send a single command via ssh and print output locally
function send-single-ssh-command () {
printf '%s\n' "$@" >&"${stdout_to_ssh_stdin}"
printf '%s\n' "echo '"$unique_eof_delimirer"'" 
>&"${stdout_to_ssh_stdin}"
print-immediate-output
}


send-single-ssh-command "find . -maxdepth 1 -name [a-z]\*" # more or less a 
standard command, that succeeds
send-single-ssh-command "ls nothin" # more or less a standard command, that 
fails

# tearing down the coprocess:
printf "%s\n" "exit" >&"${stdout_to_ssh_stdin}" # not interested in any 
more output (probably none)
wait
# Descriptors must be closed to prevent leaking.
eval "exec ${stdin_from_ssh_stdout}<&- ${stdout_to_ssh_stdin}>-"

echo "waited for the coproc to end gracefully, done"

datakanja@PBuster-NFox:/mnt/tmp$ ./test
The PID of the coproc is: 28154
./test
./out
ls: Zugriff auf 'nothin' nicht möglich: Datei oder Verzeichnis nicht gefunden
waited for the coproc to end gracefully, done
datakanja@PBuster-NFox:/mnt/tmp$



"test" is both a program and a shell builtin.  I suggest that you pick 
another, non-keyword, name for your script.



I suggest adding the Bash option "-u' (nounset).


Your file descriptor duplication, redirection, etc., seems overly 
complex.  Would not it be easier to use the coproc handles directly?


2024-06-03 08:49:41 dpchrist@laalaa ~/sandbox/bash
$ nl coproc-demo
 1  #!/usr/bin/env bash
 2  # $Id: coproc-demo,v 1.3 2024/06/03 15:49:36 dpchrist Exp $
 3  set -e
 4  set -u
 5  coproc COPROC { bash ; }
 6  echo 'echo "hello, world!"' >&"${COPROC[1]}"
 7  read -r reply <&"${COPROC[0]}"
 8  echo $reply
 9  echo "exit" >&"${COPROC[1]}"
10  wait $COPROC_PID

2024-06-03 08:49:44 dpchrist@laalaa ~/sandbox/bash
$ bash -x coproc-demo
+ set -e
+ set -u
+ echo 'echo "hello, world!"'
+ bash
+ read -r reply
+ echo hello, 'world!'
hello, world!
+ echo exit
+ wait 4229


David



Re: advanced scripting problems - or wrong approach?

2024-06-03 Thread Jonathan Dowland
On Sat Jun 1, 2024 at 8:20 AM BST, DdB wrote:
> for years have i been using a self-made backup script, that did mount a
> drive via USB, performed all kinds of plausibility checks, before
> actually backing up incrementally. Finally verifying success and logging
> the activities while kicking the ISB drive out.

I'd keep using this for now, if I were you, and work on
implementing/fixing a replacement at the same time, and only stop doing
the simple solution when the newer solution has reached the same level
of reliability.

-- 
Please do not CC me for listmail.

  Jonathan Dowland
✎j...@debian.org
   https://jmtd.net



Re: advanced scripting problems - or wrong approach?

2024-06-02 Thread DdB
Am 02.06.2024 um 02:41 schrieb DdB:
> Will share my findings, once i made more progress...

Here is what i've got before utilizing it:


> datakanja@PBuster-NFox:/mnt/tmp$ cat test 
> #!/bin/bash -e
> # testing usefulness of coprocess to control host and backup machine from a 
> single script.
> # beware: do not use subprocesses or pipes, as that will confuse the pipes 
> setup by coproc!
> # At this point, this interface may not be very flexible
> # but trying to follow best practices for using coproc in bash scripts
> # todo (deferred): how to handle stderr inside coproc?
> # todo (deferred): what, if coproc dies unexpectedly?
> 
>   # setting up the coprocess:
>   stdout_to_ssh_stdin=5 # arbitrary choice outside the range of used file 
> desciptors
>   stdin_from_ssh_stdout=6
> 
>   coproc SSH { bash; } # for testing purposes, i refrain from really 
> involving ssh just yet and replace it with bash:
> 
>   # save filedescriptors by duplicating them:
>   eval "exec ${stdin_from_ssh_stdout}<&${SSH[0]} 
> ${stdout_to_ssh_stdin}>&${SSH[1]}"
>   echo The PID of the coproc is: $SSH_PID # possibly useful for inspection
> 
> unique_eof_delimirer=""
> line=""
> # collect the output available and print it locally (synchonous):
> function print-immediate-output () {
>   while IFS= read -r -u "${stdin_from_ssh_stdout}" line
>   do
>   if [[ "${line:0-5:5}" == "$unique_eof_delimirer" ]] # currently, 
> the length is fixed
>   then
>   line="${line%}"
>   if [[ ! -z $line ]]
>   then
>   printf '%s\n' "$line"
>   fi
>   break
>   fi 
>   printf '%s\n' "$line"
>   done
> }
> 
> # send a single command via ssh and print output locally
> function send-single-ssh-command () {
>   printf '%s\n' "$@" >&"${stdout_to_ssh_stdin}"
>   printf '%s\n' "echo '"$unique_eof_delimirer"'" 
> >&"${stdout_to_ssh_stdin}"
>   print-immediate-output
> }
> 
> 
> send-single-ssh-command "find . -maxdepth 1 -name [a-z]\*" # more or less a 
> standard command, that succeeds
> send-single-ssh-command "ls nothin" # more or less a standard command, that 
> fails
> 
>   # tearing down the coprocess:
>   printf "%s\n" "exit" >&"${stdout_to_ssh_stdin}" # not interested in any 
> more output (probably none)
>   wait
>   # Descriptors must be closed to prevent leaking.
>   eval "exec ${stdin_from_ssh_stdout}<&- ${stdout_to_ssh_stdin}>-"
> 
>   echo "waited for the coproc to end gracefully, done"
> 
> datakanja@PBuster-NFox:/mnt/tmp$ ./test
> The PID of the coproc is: 28154
> ./test
> ./out
> ls: Zugriff auf 'nothin' nicht möglich: Datei oder Verzeichnis nicht gefunden
> waited for the coproc to end gracefully, done
> datakanja@PBuster-NFox:/mnt/tmp$ 



Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread DdB
Am 01.06.2024 um 16:01 schrieb Greg Wooledge:
>> i get the output from ls, but then the thing is hanging indefinitely,
>> apparently not reaching the exit line. :(
> Your first while loop never terminates.  "while read ..." continues
> running until read returns a nonzero exit status, either due to an
> error or EOF.  Your coproc never returns EOF, so the "while read"
> loop just keeps waiting for the next line of output from ls.
> 
> If you're going to communicate with a long-running process that can
> return multiple lines of output per line of input, then you have
> three choices:
> 
>   1) Arrange for some way to communicate how many lines, or bytes,
>  of output are going to be given.
> 
>   2) Send a terminator line (or byte sequence) of some kind that
>  indicates "end of current data set".
> 
>   3) Give up and assume the end of the data set after a certain amount
>  of time has elapsed with no new output arriving.  (This is usually
>  not the best choice.)
> 
> These same design issues occur in any kind of network communication, too.
> Imagine an IMAP client or something, which holds open a network connection
> to its IMAP server.  The client asks for the body of an email message,
> but needs to keep the connection open afterward so that it can ask for
> more things later.  The server has to be able to send the message back
> without closing the connection at the end.  Therefore, the IMAP protocol
> needs some way to "encapsulate" each server response, so the client
> knows when it has received the full message.

WOW!
Just wow, Greg, thank you so much!

After receiving such a wonderful hint/explanation, i did verify it being
correct and got overwhelmed with good feelings, as it allows me to learn
and experiment some more, heading in the direction of possibly solving
my initial problem.

Will share my findings, once i made more progress...

With appreciation, respect, admiration and love.
DdB




Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread David Christensen

On 6/1/24 00:20, DdB wrote:

Hello,

for years have i been using a self-made backup script, that did mount a
drive via USB, performed all kinds of plausibility checks, before
actually backing up incrementally. Finally verifying success and logging
the activities while kicking the ISB drive out.

Since a few months, i do have a real backup server instead, connecting
to it via ssh i was able to have 2 terminals open and back up manually.
Last time, i introduced a mistake by accident and since, i am trying to
automate the whole thing once again, but that is difficult, as the load
on the net is huge, mbuffer is useful in that regard. So i was intending
to have just one script for all the operations using coproc to
coordinate the 2 servers.

But weird things are going on, i cant reliably communicate between host
and backup server, at least not automatically.

Searching the web, i found:
https://github.com/reconquest/coproc.bash/blob/master/REFERENCE.md
But i was unable to get this to work, which seems to indicate, that i am
misunderstanding something.
The only success i had was to "talk" to a chess engine in a coprocess,
which did go well. But neither bash nor ssh are cooperating, i may have
timing issues with the pipes or some other side effects.

How can i describe? For example if i start this:

#!/bin/bash -e

coproc { bash; }
exec 5<&${COPROC[0]} 6>&${COPROC[1]}
fd=5

echo "ls" >&6
while IFS= read -ru $fd line
do
 printf '%s\n' "$line"
done

printf "%s\n" "sleep 3;exit" >&6
while IFS= read -ru $fd line
do
 printf '%s\n' "$line"
done

exec 5<&- 6>&-

wait
echo waited, done


i get the output from ls, but then the thing is hanging indefinitely,
apparently not reaching the exit line. :(

Anyone who can share his experience to advance my experimenting?
DdB




https://en.wikipedia.org/wiki/XY_problem


Please define the root problem you are trying to solve.


David




Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread Greg Wooledge
On Sat, Jun 01, 2024 at 09:20:59AM +0200, DdB wrote:
> > #!/bin/bash -e
> > 
> > coproc { bash; }
> > exec 5<&${COPROC[0]} 6>&${COPROC[1]}
> > fd=5
> > 
> > echo "ls" >&6
> > while IFS= read -ru $fd line
> > do
> > printf '%s\n' "$line"
> > done
> > 
> > printf "%s\n" "sleep 3;exit" >&6
> > while IFS= read -ru $fd line
> > do
> > printf '%s\n' "$line"
> > done
> > 
> > exec 5<&- 6>&-
> > 
> > wait
> > echo waited, done
> 
> i get the output from ls, but then the thing is hanging indefinitely,
> apparently not reaching the exit line. :(

Your first while loop never terminates.  "while read ..." continues
running until read returns a nonzero exit status, either due to an
error or EOF.  Your coproc never returns EOF, so the "while read"
loop just keeps waiting for the next line of output from ls.

If you're going to communicate with a long-running process that can
return multiple lines of output per line of input, then you have
three choices:

  1) Arrange for some way to communicate how many lines, or bytes,
 of output are going to be given.

  2) Send a terminator line (or byte sequence) of some kind that
 indicates "end of current data set".

  3) Give up and assume the end of the data set after a certain amount
 of time has elapsed with no new output arriving.  (This is usually
 not the best choice.)

These same design issues occur in any kind of network communication, too.
Imagine an IMAP client or something, which holds open a network connection
to its IMAP server.  The client asks for the body of an email message,
but needs to keep the connection open afterward so that it can ask for
more things later.  The server has to be able to send the message back
without closing the connection at the end.  Therefore, the IMAP protocol
needs some way to "encapsulate" each server response, so the client
knows when it has received the full message.



Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread tomas
On Sat, Jun 01, 2024 at 10:53:45AM +0200, DdB wrote:
> Am 01.06.2024 um 09:20 schrieb DdB:
> > Hello,
> > 
> I get it: you wouldnt trust my scripts.

That wasn't the point. I'm just not in the situation to
debug it at the moment.

> Thats fine with me. But my
> experience is quite different: Software, i prefer using is such, that i
> keep control.

Definitely -- that's why I concoct my backup scripts myself.
I was rather commenting at the concrete construction (that
is: concurrent processes communicating over two way pipes),
which seems somewhat fragile to me. If you haven't async
primitives, as in the shell, you might bump into deadlocks
sooner rather than later :-)

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread DdB
Am 01.06.2024 um 09:20 schrieb DdB:
> Hello,
> 
I get it: you wouldnt trust my scripts. Thats fine with me. But my
experience is quite different: Software, i prefer using is such, that i
keep control. And because backup means different things to different
people, i did not bother to explain, what i meant. (btw: i use rsync in
other places, but for backups, i do prefer zfs snapshots.)
The whole content is irrelevant to some extent. I dared to say what i want:
Stop doing backups manually and get my backup routine back, therefore
i'd love to have a single script doing exactly what i want in the exact
order i want, and as the backup takes more than one hour, i thought an
asynchronous process ould be appropriate...




Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread tomas
On Sat, Jun 01, 2024 at 08:20:08AM +, Michael Kjörling wrote:
> On 1 Jun 2024 10:11 +0200, from to...@tuxteam.de:
> >> for years have i been using a self-made backup script [...]
> > 
> > I won't get into that -- I can't even fathom why you'd need coproc
> > for a backup script. I tend to keep things simple -- they tend to
> > thank me in failing less often and in more understandable ways.
> 
> I agree. There are plenty enough of ready-made backup solutions to
> cater to different needs that making one's own shouldn't be needed.

(Full disclosure: I do mine with a shell script wrapped around
rsync, and using its wonderful "dir-merge" feature to fine tune
what to leave out).

[...]

> > I didn't try your script, but may be there is a "\n" missing down
> > there?
> > 
> >>> printf "%s\n" "sleep 3;exit" >&6
> >  ^^^
>   ^^

Good catch, thanks Michael -- to DdB: please, disregard my hunch. I
didn't look closely enough.

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread Michael Kjörling
On 1 Jun 2024 10:11 +0200, from to...@tuxteam.de:
>> for years have i been using a self-made backup script [...]
> 
> I won't get into that -- I can't even fathom why you'd need coproc
> for a backup script. I tend to keep things simple -- they tend to
> thank me in failing less often and in more understandable ways.

I agree. There are plenty enough of ready-made backup solutions to
cater to different needs that making one's own shouldn't be needed.

Depending on the format you want your backup in, it's quite possible
that a simple rsync invocation would do. rsnapshot works on top of
rsync and gives you incremental backups with history. That's what I
use (plus some surrounding homegrown scripts, particularly one to
implement a more intelligent old backups purge policy than what
rsnapshot itself offers) and it has worked near perfectly for probably
a decade.


> I didn't try your script, but may be there is a "\n" missing down
> there?
> 
>>> printf "%s\n" "sleep 3;exit" >&6
>  ^^^
  ^^

-- 
Michael Kjörling  https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”



Re: advanced scripting problems - or wrong approach?

2024-06-01 Thread tomas
On Sat, Jun 01, 2024 at 09:20:59AM +0200, DdB wrote:
> Hello,
> 
> for years have i been using a self-made backup script [...]

I won't get into that -- I can't even fathom why you'd need coproc
for a backup script. I tend to keep things simple -- they tend to
thank me in failing less often and in more understandable ways.

I didn't try your script, but may be there is a "\n" missing down
there?

> > printf "%s\n" "sleep 3;exit" >&6
 ^^^

That would be my first hunch.

Cheers
-- 
t


signature.asc
Description: PGP signature


advanced scripting problems - or wrong approach?

2024-06-01 Thread DdB
Hello,

for years have i been using a self-made backup script, that did mount a
drive via USB, performed all kinds of plausibility checks, before
actually backing up incrementally. Finally verifying success and logging
the activities while kicking the ISB drive out.

Since a few months, i do have a real backup server instead, connecting
to it via ssh i was able to have 2 terminals open and back up manually.
Last time, i introduced a mistake by accident and since, i am trying to
automate the whole thing once again, but that is difficult, as the load
on the net is huge, mbuffer is useful in that regard. So i was intending
to have just one script for all the operations using coproc to
coordinate the 2 servers.

But weird things are going on, i cant reliably communicate between host
and backup server, at least not automatically.

Searching the web, i found:
https://github.com/reconquest/coproc.bash/blob/master/REFERENCE.md
But i was unable to get this to work, which seems to indicate, that i am
misunderstanding something.
The only success i had was to "talk" to a chess engine in a coprocess,
which did go well. But neither bash nor ssh are cooperating, i may have
timing issues with the pipes or some other side effects.

How can i describe? For example if i start this:
> #!/bin/bash -e
> 
> coproc { bash; }
> exec 5<&${COPROC[0]} 6>&${COPROC[1]}
> fd=5
> 
> echo "ls" >&6
> while IFS= read -ru $fd line
> do
> printf '%s\n' "$line"
> done
> 
> printf "%s\n" "sleep 3;exit" >&6
> while IFS= read -ru $fd line
> do
> printf '%s\n' "$line"
> done
> 
> exec 5<&- 6>&-
> 
> wait
> echo waited, done

i get the output from ls, but then the thing is hanging indefinitely,
apparently not reaching the exit line. :(

Anyone who can share his experience to advance my experimenting?
DdB



Re: interface/network scripting - how to?

2022-02-06 Thread David Wright
On Fri 04 Feb 2022 at 19:14:45 (+0100), Kamil Jońca wrote:
> 
> Current situation:
> debian laptop with interfaces defined in /etc/network/interfaces
> + resolvconf package and bunch of scripts wchich configures network
> (routes and name resolving) according to interfaces/vpn up down.
> For example
> 1.  I am connected to  home1 network (connected by wifi, no default
> routing ), this network sets routing to some subnets with dhcp option
> 121 (and dhclient scripts handles this)
> 2. I am connected via etch to router with default gateway
> 3. I am connected to work1 network via openvpn tunnel.
> 4. I am connected to work2 network via ipsec gateway.

As you can see from Anssi Saari's reply, it sometimes helps
to give a bit more information than the above in order to
trigger more responses.

> I want to (and with my current config this is done)
> that:
> 1. proper routes are established (especially these with option 121)
> 2. name resolving is properly configured:
>   ie. home1.tld DNS queries are passed to home1 network
>   work1.tld DNS queries are passed to work1 network (via openvpn tunnel)
>   work2.tld DNS queries are passed to work2 network (via ipsec tunnel)
> I am quite happy with my current config but sometimes I can read that
> /etc/network/interfaces is "deprecated" in favor of systemd-networkd or
> netplan.
> So I have two questions:
> 1. Should I prepare migration?

It's often worth having a second string just in case something ceases
to work. (But I've not seen deprecation mentioned either.) So, for
example, I've been chacking out iwd, since wicd has now gone.

> 2. How these things can be achieved with systemd-networkd? I read the
> manuals, but I was not able to find working examples and I am not sure
> where can I start.

I guess you've read things like   man systemd-networkd,
man   systemd.network   and   man systemd.netdev,   but the
numerous examples at the end of the latter two might yield
some good search terms to turn up further information.

There may be some extra info in the Arch wikis, but the Debian
ones seem to just regurgitate the man pages.

Cheers,
David.



Re: interface/network scripting - how to?

2022-02-05 Thread Kamil Jońca
Anssi Saari  writes:

> Kamil Jońca  writes:
>
>> 2. name resolving is properly configured:
>>   ie. home1.tld DNS queries are passed to home1 network
>>   work1.tld DNS queries are passed to work1 network (via openvpn tunnel)
>>   work2.tld DNS queries are passed to work2 network (via ipsec tunnel)
>
> So how have you setup this part? I always thought this needs a local
> name server, such as systemd-networkd provides and which I switched to
> once I heard it had been implemented. Before I had just wobbly
> resolvconf which usually got the DNS setup wrong. I managed fix it so it
> was mostly OK but it was never good.
Point for you. :)
I forgot to mention about dnsmasq, whose configuration is updated by
scripts.

KJ
-- 
http://stopstopnop.pl/stop_stopnop.pl_o_nas.html



Re: interface/network scripting - how to?

2022-02-05 Thread Anssi Saari
Kamil Jońca  writes:

> 2. name resolving is properly configured:
>   ie. home1.tld DNS queries are passed to home1 network
>   work1.tld DNS queries are passed to work1 network (via openvpn tunnel)
>   work2.tld DNS queries are passed to work2 network (via ipsec tunnel)

So how have you setup this part? I always thought this needs a local
name server, such as systemd-networkd provides and which I switched to
once I heard it had been implemented. Before I had just wobbly
resolvconf which usually got the DNS setup wrong. I managed fix it so it
was mostly OK but it was never good.

> I am quite happy with my current config but sometimes I can read that
> /etc/network/interfaces is "deprecated" in favor of systemd-networkd or
> netplan.

I never heard that.

> So I have two questions:
> 1. Should I prepare migration?

If you're happy with the setup, I don't see why. Well, if you like to
learn new things, sure, go for it. I just find it a bit of pain to make
major changes to my network. I did recently replace my router but since
it was just a router for wired connections it was fairly easy to replace
it once I had configured the new one.

> 2. How these things can be achieved with systemd-networkd? I read the
> manuals, but I was not able to find working examples and I am not sure
> where can I start.

I do have a similar if simpler setup, I just have a single VPN (openvpn)
connection to the internet and have a local network of a few
machines. DNS queries go either to my router or the VPN provider's DNS,
depending on the interface.

I can't remember how I got started with systemd-networkd, it's been a
few years. Internet searches probably. systemd documentation is a decent
reference but as such they don't usually tell you how to build something
specific. I don't remember any particular difficulty in finding pages on
how to get started.



Re: interface/network scripting - how to?

2022-02-04 Thread Kamil Jońca
john doe  writes:

[..]
>
>> 2. How these things can be achieved with systemd-networkd? I read the
>> manuals, but I was not able to find working examples and I am not sure
>> where can I start.
>>
>
> The Systemd mailing lists!

Thanks. Will try.
KJ

-- 
http://stopstopnop.pl/stop_stopnop.pl_o_nas.html



Re: interface/network scripting - how to?

2022-02-04 Thread john doe

On 2/4/2022 7:14 PM, Kamil Jońca wrote:


Current situation:
debian laptop with interfaces defined in /etc/network/interfaces
+ resolvconf package and bunch of scripts wchich configures network
(routes and name resolving) according to interfaces/vpn up down.
For example
1.  I am connected to  home1 network (connected by wifi, no default
 routing ), this network sets routing to some subnets with dhcp option
 121 (and dhclient scripts handles this)
2. I am connected via etch to router with default gateway
3. I am connected to work1 network via openvpn tunnel.
4. I am connected to work2 network via ipsec gateway.

I want to (and with my current config this is done)
that:
1. proper routes are established (especially these with option 121)
2. name resolving is properly configured:
   ie. home1.tld DNS queries are passed to home1 network
   work1.tld DNS queries are passed to work1 network (via openvpn tunnel)
   work2.tld DNS queries are passed to work2 network (via ipsec tunnel)
I am quite happy with my current config but sometimes I can read that
/etc/network/interfaces is "deprecated" in favor of systemd-networkd or
netplan.
So I have two questions:
1. Should I prepare migration?


I would not put that on the front burner but experimenting with Systemd
might not be a bad idea.


2. How these things can be achieved with systemd-networkd? I read the
manuals, but I was not able to find working examples and I am not sure
where can I start.



The Systemd mailing lists!

--
John Doe



Re: interface/network scripting - how to?

2022-02-04 Thread tomas
On Fri, Feb 04, 2022 at 01:33:54PM -0500, Greg Wooledge wrote:
> On Fri, Feb 04, 2022 at 07:14:45PM +0100, Kamil Jońca wrote:
> > I am quite happy with my current config but sometimes I can read that
> > /etc/network/interfaces is "deprecated" in favor of systemd-networkd or
> > netplan.
> 
> Where did you read this?  Sounds like Red Hat or XDG or systemd propaganda.

I wouldn't hope that either!

That said, those things will stay alive as long as there are folks who
care.

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: interface/network scripting - how to?

2022-02-04 Thread Greg Wooledge
On Fri, Feb 04, 2022 at 07:14:45PM +0100, Kamil Jońca wrote:
> I am quite happy with my current config but sometimes I can read that
> /etc/network/interfaces is "deprecated" in favor of systemd-networkd or
> netplan.

Where did you read this?  Sounds like Red Hat or XDG or systemd propaganda.

> So I have two questions:
> 1. Should I prepare migration?

Given that you're happy with your current setup, I see no reason to do so.



interface/network scripting - how to?

2022-02-04 Thread Kamil Jońca


Current situation:
debian laptop with interfaces defined in /etc/network/interfaces
+ resolvconf package and bunch of scripts wchich configures network
(routes and name resolving) according to interfaces/vpn up down.
For example
1.  I am connected to  home1 network (connected by wifi, no default
routing ), this network sets routing to some subnets with dhcp option
121 (and dhclient scripts handles this)
2. I am connected via etch to router with default gateway
3. I am connected to work1 network via openvpn tunnel.
4. I am connected to work2 network via ipsec gateway.

I want to (and with my current config this is done)
that:
1. proper routes are established (especially these with option 121)
2. name resolving is properly configured:
  ie. home1.tld DNS queries are passed to home1 network
  work1.tld DNS queries are passed to work1 network (via openvpn tunnel)
  work2.tld DNS queries are passed to work2 network (via ipsec tunnel)
I am quite happy with my current config but sometimes I can read that
/etc/network/interfaces is "deprecated" in favor of systemd-networkd or
netplan.
So I have two questions:
1. Should I prepare migration?
2. How these things can be achieved with systemd-networkd? I read the
manuals, but I was not able to find working examples and I am not sure
where can I start.
  
KJ

-- 
http://wolnelektury.pl/wesprzyj/teraz/



Re: [HS] Scripting Bash

2019-04-05 Thread Étienne Mollier
Sébastien Nobili, au 2019-04-04 :
> Attention toutefois aux bashismes. Bash
> fournit pas mal d’adaptations au standard (Bourne Shell) qui rendent
> non-standard les scripts écrits pour lui et testés avec lui.
>
> Pas de problème si on n’utilise que Bash, mais si un jour le shell change (par
> exemple lorsque Debian est passé de Bash à Dash comme shell par défaut), alors
> les scripts plantent (et en général avec des messages assez obscurs).

Bonjour,

C'est une très bonne remarque, un certain nombre de fonctions
avancées de Bash ne peuvent pas être utilisée avec n'importe
quel shell.  Le Dash a la vocation d'implémenter le standard, ni
plus, ni moins.  Un script compatible Dash est donc censé
tourner de la même manière avec n'importe quel autre shell
compatible avec le Bourne Shell standard, du moins en théorie.

Quand un shell est appelé de manière implicite, typiquement pour
interpréter les recettes dans un Makefile, les bashismes peuvent
causer des dégâts.  Et changer de shell dans ce genre de
contexte n'est pas toujours évident : je viens seulement de
découvrir l'existence de la variable SHELL dans make pour
changer d'interpréteur, par exemple…

Amicalement,
-- 
Étienne Mollier 




[HS] Scripting Bash (Re: mais ou est passee la place manquante ?)

2019-04-05 Thread Sébastien NOBILI
Bonjour,

Le jeudi 04 avril 2019 à 23:50, hamster a écrit :
> Le 04/04/2019 à 23:21, Étienne Mollier a écrit :
> > Pour aller plus loin, l'Advanced Bash Scripting guide est pour
> > moi un incontournable :
> >
> > http://www.tldp.org/LDP/abs/html/index.html
> 
> Je note le lien. J'ai déjà fait des recherches de tutos pour faire des
> scripts shell mais comme souvent je me suis perdu dans la profusion.
> Trop de tutos tuent les tutos et les liens vers les références de
> qualité deviennent un bien précieux.

Je confirme la qualité de ce guide. Attention toutefois aux bashismes. Bash
fournit pas mal d’adaptations au standard (Bourne Shell) qui rendent
non-standard les scripts écrits pour lui et testés avec lui.

Pas de problème si on n’utilise que Bash, mais si un jour le shell change (par
exemple lorsque Debian est passé de Bash à Dash comme shell par défaut), alors
les scripts plantent (et en général avec des messages assez obscurs).

Pour éviter de se faire piéger (au choix) :
- éviter les bashismes (et faire du scripting standard)
- forcer l’utilisation de bash dans le shebang

Sébastien



Re: quick scripting 'is /P/Q mounted'

2018-03-14 Thread Mark Fletcher
On Tue, Mar 13, 2018 at 03:56:00PM -0400, The Wanderer wrote:
> On 2018-03-13 at 15:39, Joe wrote:
> 
> > On Tue, 13 Mar 2018 14:49:56 +0100  wrote:
> 
> That test can be spoofed, however, by the creation of a directory with
> the same name (and/or other characteristics) under the mount point while
> the mount is not active.
> 

Yes, but in most use cases one would not be worried about malicious 
actions, you are trying to protect against cock-ups.

> Even if you don't think anything malicious is ever going to try to spoof
> this in whatever case is at hand, can you be sure no script (or, for
> that matter, user) will ever attempt to create that directory under the
> mistaken impression that the mount is active?
> 

Yeah, that's a fair point though.

Mark



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Joe
On Tue, 13 Mar 2018 15:56:00 -0400
The Wanderer  wrote:

> On 2018-03-13 at 15:39, Joe wrote:
> 
> > On Tue, 13 Mar 2018 14:49:56 +0100  wrote:  
> 
> >> On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote:  
> 
> >>> Unless I've misunderstood the question, you can tell if
> >>> something is mounted at a mount point by checking if anything is
> >>> present under the mount point [...]  
> >> 
> >> Not if the file system is really empty (and no, lost+found doesn't 
> >> really count, since not all file systems have that).  
> > 
> > But one use-case is unattended synchronisation, possibly over a
> > network. If the directory is mounted, but with some kind of problem,
> > then a check for mounting could succeed without any data being
> > visible to the synchronising application. In the worst case, the
> > backup directory might be synchronised to an apparently empty
> > one
> > 
> > I prefer to test for the existence of a known lower directory in
> > this case, which tests not only for mounting but for a successful
> > read.  
> 
> That test can be spoofed, however, by the creation of a directory with
> the same name (and/or other characteristics) under the mount point
> while the mount is not active.
> 
> Even if you don't think anything malicious is ever going to try to
> spoof this in whatever case is at hand, can you be sure no script
> (or, for that matter, user) will ever attempt to create that
> directory under the mistaken impression that the mount is active?
> 

Reasonably, because the only program likely to create it would be the
synchroniser itself, which should have been prevented from running
because it wasn't there to start with. If it did happen, nothing
would be getting wiped, just a spurious copy created on a drive that
doesn't contain any system stuff, so I wouldn't worry too much. The
wiping of one of the sync targets *might* be catastrophic (and might
lead to the other getting wiped on the next sync) and is completely
unacceptable.

Yes, synchronisers do have some protection against this kind of error,
but I like to use belt, braces, and skyhooks when available.

Should I worry about your scenario, I could take it further, with
utterly improbably-named directories or files containing specific data,
but so far I haven't.

-- 
Joe

-- 
Joe



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, Mar 13, 2018 at 03:56:00PM -0400, The Wanderer wrote:
> On 2018-03-13 at 15:39, Joe wrote:

[...]

> > I prefer to test for the existence of a known lower directory in
> > this case, which tests not only for mounting but for a successful
> > read.
> 
> That test can be spoofed, however, by the creation of a directory with
> the same name (and/or other characteristics) under the mount point while
> the mount is not active.
> 
> Even if you don't think anything malicious is ever going to try to spoof
> this in whatever case is at hand, can you be sure no script (or, for
> that matter, user) will ever attempt to create that directory under the
> mistaken impression that the mount is active?

Seconded. That depends on what you want to achieve, but if this is some
kind of backup script, if it manages once (by mistake) to sync to the
mount point while no mount is active, it'll keep repeating that mistake
forever...

Cheers
- -- tomás
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlqoM9MACgkQBcgs9XrR2kbJfwCdE45msW7x44N4Ma+HQb57oZKO
gMAAnivPzGgYCRXAs6xRRBfVzYwfnrYm
=pRcJ
-END PGP SIGNATURE-



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread The Wanderer
On 2018-03-13 at 15:39, Joe wrote:

> On Tue, 13 Mar 2018 14:49:56 +0100  wrote:

>> On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote:

>>> Unless I've misunderstood the question, you can tell if
>>> something is mounted at a mount point by checking if anything is
>>> present under the mount point [...]
>> 
>> Not if the file system is really empty (and no, lost+found doesn't 
>> really count, since not all file systems have that).
> 
> But one use-case is unattended synchronisation, possibly over a
> network. If the directory is mounted, but with some kind of problem,
> then a check for mounting could succeed without any data being
> visible to the synchronising application. In the worst case, the
> backup directory might be synchronised to an apparently empty
> one
> 
> I prefer to test for the existence of a known lower directory in
> this case, which tests not only for mounting but for a successful
> read.

That test can be spoofed, however, by the creation of a directory with
the same name (and/or other characteristics) under the mount point while
the mount is not active.

Even if you don't think anything malicious is ever going to try to spoof
this in whatever case is at hand, can you be sure no script (or, for
that matter, user) will ever attempt to create that directory under the
mistaken impression that the mount is active?

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man. -- George Bernard Shaw



signature.asc
Description: OpenPGP digital signature


Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Joe
On Tue, 13 Mar 2018 14:49:56 +0100
 wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote:

> > >   
> > Unless I've misunderstood the question, you can tell if something
> > is mounted at a mount point by checking if anything is present
> > under the mount point [...]  
> 
> Not if the file system is really empty (and no, lost+found doesn't
> really count, since not all file systems have that).
> 

But one use-case is unattended synchronisation, possibly over a network.
If the directory is mounted, but with some kind of problem, then a check
for mounting could succeed without any data being visible to the
synchronising application. In the worst case, the backup directory
might be synchronised to an apparently empty one

I prefer to test for the existence of a known lower directory in this
case, which tests not only for mounting but for a successful read.

-- 
Joe



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Greg Wooledge
On Tue, Mar 13, 2018 at 07:51:32AM -0700, Mike McClain wrote:
> Thank you Richard.
> I suspect $(grep /south40/docs/ /proc/mounts) would be faster than

But that would be wrong, because it would incorrectly return "true"
if you have something mounted at /south40/docs/subdir or /media/south40/docs/
(or if there is a device that contains the string "/south40/docs/"
somewhere in its name, etc.).

Use the mountpoint command instead.  This is why it exists.  (Use the
-q option in a shell script to suppress the human-readable output.)



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Mike McClain
Thank you Richard.
I suspect $(grep /south40/docs/ /proc/mounts) would be faster than
$( mount | grep 'south40/docs').
And I'm sure [ -f /south40/docs/.flag ] would be.
Much obliged.
Mike

On Tue, Mar 13, 2018 at 05:37:07PM +1300, Richard Hector wrote:
> On 13/03/18 16:40, Mike McClain wrote:
> > If my other computer is South40 and I want to mount South40's /docs
> > on my /south40/docs/ directory I can do that. As one script calls
> > another I want to know if I need to mount South40 without
> > $( mount | grep 'south40/docs').
>
> You could look at /proc/mounts, but that's similar to the output of mount.
>
> Or if it's for a specific directory, and you can put something in it,
> you can test for the existence of a special file in the directory.
>
> Something like
>
> [ -f /south40/docs/.flag ]
>
> Richard
>
--
"Any intelligent fool can make things bigger and more complex...
It takes a touch of genius - and a lot of courage to move in the
opposite direction."   - Albert Einstein



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Mike McClain
Thank you David.
As it happens I have util-linux installed but as with most of Gnu/Linux
there are hundreds of programs I've never used and don't know what do.
Appreciate the heads-up.
Mike

On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote:
> On 13 March 2018 at 14:40, Mike McClain  wrote:
> >
> > If my other computer is South40 and I want to mount South40's /docs
> > on my /south40/docs/ directory I can do that. As one script calls
> > another I want to know if I need to mount South40 without
> > $( mount | grep 'south40/docs').
> >
> > Suggestions?
>
> Installing the package util-linux will provide the mountpoint command
> which exits true=0 if its argument is in use as a mountpoint. Example:
>
> $ if mountpoint / ; then echo "exit status is $?" ; fi
> / is a mountpoint
> exit status is 0

--
"Any intelligent fool can make things bigger and more complex...
It takes a touch of genius - and a lot of courage to move in the
opposite direction."   - Albert Einstein



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, Mar 13, 2018 at 10:33:43PM +0900, Mark Fletcher wrote:
> On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote:
> > On 13 March 2018 at 14:40, Mike McClain  wrote:
> > >
> > > If my other computer is South40 and I want to mount South40's /docs
> > > on my /south40/docs/ directory I can do that. As one script calls
> > > another I want to know if I need to mount South40 without
> > > $( mount | grep 'south40/docs').
> > >
> > > Suggestions?
> > 
> > Installing the package util-linux will provide the mountpoint command
> > which exits true=0 if its argument is in use as a mountpoint. Example:
> > 
> > $ if mountpoint / ; then echo "exit status is $?" ; fi
> > / is a mountpoint
> > exit status is 0
> > 
> Unless I've misunderstood the question, you can tell if something is 
> mounted at a mount point by checking if anything is present under the 
> mount point [...]

Not if the file system is really empty (and no, lost+found doesn't really
count, since not all file systems have that). Watch this:

  tomas@trotzki:~$ dd if=/dev/zero of=fatty bs=1024 count=1024
  1024+0 records in
  1024+0 records out
  1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00582808 s, 180 MB/s
  tomas@trotzki:~$ mkfs.vfat fatty
  bash: mkfs.vfat: command not found
  tomas@trotzki:~$ /sbin/mkfs.vfat fatty
  mkfs.fat 4.1 (2017-01-24)
  tomas@trotzki:~$ sudo mount -ouid=tomas,gid=tomas fatty /mnt
  [sudo] password for tomas: 
  tomas@trotzki:~$ ls -al /mnt
  total 20
  drwxr-xr-x  2 tomas tomas 16384 Jan  1  1970 .
  drwxr-xr-x 23 root  root   4096 Feb 23 12:42 ..

Totally empty...

Conversely, the directory you mount things on doesn't have to be empty:
its contents is just shadowed while the mount lasts.

Cheers
- -- tomás
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlqn1wQACgkQBcgs9XrR2kZE2QCfeYUbeissCPgETJSIu/LGKLM+
sMEAniUti1S3RLk6lfIhhrb7fUY5damO
=uJRD
-END PGP SIGNATURE-



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread Mark Fletcher
On Tue, Mar 13, 2018 at 08:49:58PM +1100, David wrote:
> On 13 March 2018 at 14:40, Mike McClain  wrote:
> >
> > If my other computer is South40 and I want to mount South40's /docs
> > on my /south40/docs/ directory I can do that. As one script calls
> > another I want to know if I need to mount South40 without
> > $( mount | grep 'south40/docs').
> >
> > Suggestions?
> 
> Installing the package util-linux will provide the mountpoint command
> which exits true=0 if its argument is in use as a mountpoint. Example:
> 
> $ if mountpoint / ; then echo "exit status is $?" ; fi
> / is a mountpoint
> exit status is 0
> 
Unless I've misunderstood the question, you can tell if something is 
mounted at a mount point by checking if anything is present under the 
mount point, eg if you know there is a directory /Y that gets mounted 
under mount point /X, you can can make sure /X/Y doesn't exist under the 
mount poiunt and then check for the existence of /X/Y -- it will be 
there if the mount point is in use and not if not.

Mark



Re: quick scripting 'is /P/Q mounted'

2018-03-13 Thread David
On 13 March 2018 at 14:40, Mike McClain  wrote:
>
> If my other computer is South40 and I want to mount South40's /docs
> on my /south40/docs/ directory I can do that. As one script calls
> another I want to know if I need to mount South40 without
> $( mount | grep 'south40/docs').
>
> Suggestions?

Installing the package util-linux will provide the mountpoint command
which exits true=0 if its argument is in use as a mountpoint. Example:

$ if mountpoint / ; then echo "exit status is $?" ; fi
/ is a mountpoint
exit status is 0



Re: quick scripting 'is /P/Q mounted'

2018-03-12 Thread Richard Hector
On 13/03/18 16:40, Mike McClain wrote:
> A while back, Pierre Gaston posted this little tidbit to quickly
> determine if my network is up:
> [ "$( 
> Now I wonder if there is a similar file in /sys that would tell if
> anything is mounted on a particular directory. I've browsed /sys but
> not found what I'm looking for.
> 
> If my other computer is South40 and I want to mount South40's /docs
> on my /south40/docs/ directory I can do that. As one script calls
> another I want to know if I need to mount South40 without
> $( mount | grep 'south40/docs').

You could look at /proc/mounts, but that's similar to the output of mount.

Or if it's for a specific directory, and you can put something in it,
you can test for the existence of a special file in the directory.

Something like

[ -f /south40/docs/.flag ]

Richard




signature.asc
Description: OpenPGP digital signature


quick scripting 'is /P/Q mounted'

2018-03-12 Thread Mike McClain
A while back, Pierre Gaston posted this little tidbit to quickly
determine if my network is up:
[ "$(

Re: Problème "basique" de scripting...

2017-09-11 Thread Raphaël POITEVIN
Étienne Mollier  writes:
> Cette solution me semble sérieusement légitime, donc si quelqu'un
> y voit une énormité, qu'il n'hésite pas à le signaler, faut pas
> blaguer avec `rm`, même le vendredi.

Surtout le vendredi ! :-)
-- 
Raphaël POITEVIN



Re: Problème "basique" de scripting...

2017-09-08 Thread Étienne Mollier

On 09/08/2017 08:58 PM, Francois Lafont wrote:
> On 09/08/2017 06:41 PM, Gilles Mocellin wrote:
> 
>> rm -f /etc/apt/source.list.d/*
>>
>> Et c'est tout...
>> S'il n'y a pas de fichier, il ne fait rien, et ne sort pas d'erreur grace à 
>> l'option -f.
> 
> ... sauf si le répertoire /etc/apt/source.list.d/ contient un
> sous répertoire.
> 
> Bon ok, je pinaille. :p
> 

Bonsoir François,

Vous pinaillez, oui et non,

Si en-tête, le script a un `set -e` pour arrêter les frais en cas
d'erreur, la présence d'un répertoire va stopper la procédure.

J'aurais plutôt commis une purge dans le répertoire de sources de
la manière suivante.  Si on force récursivement l'effacement du
répertoire "/etc/apt/sources.list.d" tout entier, pas de risque
de piège avec les astérisques puisqu'il n'y en a pas.  ;)

Cette solution me semble sérieusement légitime, donc si quelqu'un
y voit une énormité, qu'il n'hésite pas à le signaler, faut pas
blaguer avec `rm`, même le vendredi.


Votre solution à base de `find` était très bien, j'aurais raffiné
encore un peu en ajoutant les fichiers .sources et en prenant en
compte la majorité des types de fichiers, dès fois qu'un petit
malin trouve le moyen de positionner un lien symbolique ou
(soyons fous) une socket avec potentiellement de tout dedans :

find /etc/apt/sources.list.d/   \
-maxdepth 1 -mindepth 1 \
-not -type d\
-name '*.list' -or -name '*.sources'\
-delete

À plus,
-- 
Étienne Mollier 



Re: Problème "basique" de scripting...

2017-09-08 Thread Francois Lafont
On 09/08/2017 06:41 PM, Gilles Mocellin wrote:

> rm -f /etc/apt/source.list.d/*
> 
> Et c'est tout...
> S'il n'y a pas de fichier, il ne fait rien, et ne sort pas d'erreur grace à 
> l'option -f.

... sauf si le répertoire /etc/apt/source.list.d/ contient un
sous répertoire.

Bon ok, je pinaille. :p

-- 
François Lafont



Re: Problème "basique" de scripting...

2017-09-08 Thread Gilles Mocellin
On vendredi 8 septembre 2017 13:01:48 CEST Marc Chantreux wrote:
> salut,
> 
> si tu mets ton * dans une chaine (""), c'est pour dire que tu cherches
> un fichier qui s'appelle litteralement *.
> 
> ce que tu cherches a faire c'est
> 
>   test /etc/apt/sources.list.d/* &&
> rm /etc/apt/sources.list.d/*
> 
> autre approche (intéressante si beaucoup de fichiers)
> 
>   find /etc/apt/sources.list.d -prune -maxdepth 1 -print0 |
>   xargs -0 rm

Bonsoir,

Pour vous embetez, la commande rm n'est pas si gourmande. Pour quoi ne 
l'exécuter que s'il y a des fichiers ?

rm -f /etc/apt/source.list.d/*

Et c'est tout...
S'il n'y a pas de fichier, il ne fait rien, et ne sort pas d'erreur grace à 
l'option -f.



Re: Problème "basique" de scripting...

2017-09-08 Thread David BERCOT
Re-bonjour,

C'est tout à fait ça ;-)
Il ne marchait pas avant mais je ne m'en rendais pas compte vu qu'il n'y
a plus eu aucun fichier ajouté dans le répertoire...
Le find est effectivement une solution plus adaptée...

Merci à tous pour vos réponses.

David.

Le 08/09/2017 à 12:14, Francois Lafont a écrit :
> Hello,
> 
> On 09/08/2017 11:57 AM, David BERCOT wrote:
> 
>> if [ -e "/etc/apt/sources.list.d/*" ]
>> then
>> rm /etc/apt/sources.list.d/*
>> fi
> 
> Je ne suis pas sûr d'avoir compris comment était
> ton code à l'origine mais je pense qu'il n'était
> pas correct (ce qui ne l'a pas empêché de marcher
> pendant un certain temps semble-t-il).
> 
> Avec les doubles quotes, tu demandes à bash de
> tester si un fichier qui s'appelle * (avec vraiment
> comme nom juste le caractère *) existe dans le
> répertoire /etc/apt/sources.list.d/. Et on imagine
> bien que ce n'est pas ce que tu veux demander à
> bash.
> 
> Sans les doubles quotes, là le caractère * devient
> spécial et bash le développe en fonction de ce qu'il
> y a dans ton répertoire.
> 
> Par exemple si dans /etc/apt/sources.list.d/, tu as
> titi.list et toto.list (et c'est tout) alors tout
> va se passer comme si tu avais écris :
> 
> [ -e /etc/apt/sources.list.d/titi.list /etc/apt/sources.list.d/toto.list ]
> 
> et là tu as fort logiquement une erreur vu que -e
> n'accepte _qu'un seul_ argument, pas plus. D'où le
> message d'erreur que tu obtiens.
> 
> Si le répertoire ne contenait qu'un seul fichier, là
> ça marcherait. En fait, sans les "...", le code marche
> mais juste pour 0 ou 1 fichier dans le répertoire, pas
> plus. :)
> 
> Perso, si je peux éviter les * dans un script, je le
> fais, surtout pour du rm. À ta place je ferais plutôt ceci :
> 
> find /etc/apt/sources.list.d/ -maxdepth 1 -mindepth 1 -type f -delete
> 
> voire, tant qu'on y ait :
> 
> find /etc/apt/sources.list.d/ -maxdepth 1 -mindepth 1 -type f -name 
> '*.list' -delete
> 
> J'espère que c'est plus clair pour toi maintenant.
> À+
> 
> --
> François Lafont
> 
> 



Re: Problème "basique" de scripting...

2017-09-08 Thread Marc Chantreux
On Fri, Sep 08, 2017 at 01:42:47PM +0200, Francois Lafont wrote:
> > ce que tu cherches a faire c'est
> > 
> >   test /etc/apt/sources.list.d/* &&
> >   rm /etc/apt/sources.list.d/*

> root@stretch-clean:~# test /etc/apt/sources.list.d/*
> -bash: test: /etc/apt/sources.list.d/docker.list: unary operator expected 

oops ... effectivement :) utilise find !



Re: Problème "basique" de scripting...

2017-09-08 Thread Francois Lafont
On 09/08/2017 01:01 PM, Marc Chantreux wrote:

> ce que tu cherches a faire c'est
> 
>   test /etc/apt/sources.list.d/* &&
> rm /etc/apt/sources.list.d/*

root@stretch-clean:~# ls /etc/apt/sources.list.d/
titi.list  toto.list

root@stretch-clean:~# test /etc/apt/sources.list.d/*
-bash: test: /etc/apt/sources.list.d/docker.list: unary operator expected

-- 
François Lafont



Re: Problème "basique" de scripting...

2017-09-08 Thread Jean-Marc
Fri, 8 Sep 2017 11:57:50 +0200
David BERCOT  écrivait :

> Bonjour,

salut David,

> 
> Je viens de ré-installer mon système suite à un plantage et,
> bizarrement, un script tout simple ne fonctionne plus correctement.
> Malgré divers tests et recherches, j'avoue que  je ne comprends pas bien...
> 
> Le voici :
> #!/bin/bash
> 
> if [ -e "/etc/apt/sources.list.d/*" ]
> then
>     rm /etc/apt/sources.list.d/*
> fi
> 
> En doublant les crochets, ça ne change rien.
> En supprimant les quotes, j'ai l'erreur suivante : ligne 3 : [: trop
> d'arguments (que je ne comprends pas non plus d'ailleurs)...

D'après la doc de bash :
test - file
  Vrai si le fichier existe.

Vérifie si "/etc/apt/sources.list.d/*" ne retoune pas plusieurs fichiers.
Ce qui pourrait expliquer l'erreur 'trop d'arguments'

> J'ai bien des fichiers dans /etc/apt/sources.lists.d/ [je coupe court à
> tout commentaire sur le sujet : ce n'est pas le problème ;-)] mais il
> fait comme si ce n'était pas le cas.
> 
> Auriez-vous une piste ?
> 
> Merci d'avance.

J'espère que cela t'aidera.

> 
> David.
> 


Jean-Marc 


pgppkcVScCZzr.pgp
Description: PGP signature


Re: Problème "basique" de scripting...

2017-09-08 Thread Marc Chantreux
salut,

si tu mets ton * dans une chaine (""), c'est pour dire que tu cherches
un fichier qui s'appelle litteralement *.

ce que tu cherches a faire c'est

  test /etc/apt/sources.list.d/* &&
  rm /etc/apt/sources.list.d/*

autre approche (intéressante si beaucoup de fichiers)

  find /etc/apt/sources.list.d -prune -maxdepth 1 -print0 |
xargs -0 rm

cordialement,
marc



Re: Problème "basique" de scripting...

2017-09-08 Thread JF Straeten

Hello,

On Fri, Sep 08, 2017 at 11:57:50AM +0200, David BERCOT wrote:

[...]
> Le voici :
> #!/bin/bash
> 
> if [ -e "/etc/apt/sources.list.d/*" ]
> then
>     rm /etc/apt/sources.list.d/*
> fi

[...]
> Auriez-vous une piste ?

Ça s'exécute forcément en root, je suppose ?

Essaye un peu de coder le path de 'rm' en dur, sans reposer sur
$PATH. Donc :

[...]

/bin/rm /etc/apt/sources.list.d/*


Qu'est-ce que ça donne ?

A+

-- 

JFS.



Re: Problème "basique" de scripting...

2017-09-08 Thread Francois Lafont
On 09/08/2017 12:07 PM, Raphaël POITEVIN wrote:

> il manque un ; après le ]

Je ne pense pas.

On peut écrire :

if [ -e "$fichier" ]
then
   ...

Le « ; » est nécessaire si on met le then sur la
même ligne :

if [ -e "$fichier" ]; then
   ...

Perso, j'utilise toujours la première forme.

-- 
François Lafont



Re: Problème "basique" de scripting...

2017-09-08 Thread Francois Lafont
Hello,

On 09/08/2017 11:57 AM, David BERCOT wrote:

> if [ -e "/etc/apt/sources.list.d/*" ]
> then
> rm /etc/apt/sources.list.d/*
> fi

Je ne suis pas sûr d'avoir compris comment était
ton code à l'origine mais je pense qu'il n'était
pas correct (ce qui ne l'a pas empêché de marcher
pendant un certain temps semble-t-il).

Avec les doubles quotes, tu demandes à bash de
tester si un fichier qui s'appelle * (avec vraiment
comme nom juste le caractère *) existe dans le
répertoire /etc/apt/sources.list.d/. Et on imagine
bien que ce n'est pas ce que tu veux demander à
bash.

Sans les doubles quotes, là le caractère * devient
spécial et bash le développe en fonction de ce qu'il
y a dans ton répertoire.

Par exemple si dans /etc/apt/sources.list.d/, tu as
titi.list et toto.list (et c'est tout) alors tout
va se passer comme si tu avais écris :

[ -e /etc/apt/sources.list.d/titi.list /etc/apt/sources.list.d/toto.list ]

et là tu as fort logiquement une erreur vu que -e
n'accepte _qu'un seul_ argument, pas plus. D'où le
message d'erreur que tu obtiens.

Si le répertoire ne contenait qu'un seul fichier, là
ça marcherait. En fait, sans les "...", le code marche
mais juste pour 0 ou 1 fichier dans le répertoire, pas
plus. :)

Perso, si je peux éviter les * dans un script, je le
fais, surtout pour du rm. À ta place je ferais plutôt ceci :

find /etc/apt/sources.list.d/ -maxdepth 1 -mindepth 1 -type f -delete

voire, tant qu'on y ait :

find /etc/apt/sources.list.d/ -maxdepth 1 -mindepth 1 -type f -name 
'*.list' -delete

J'espère que c'est plus clair pour toi maintenant.
À+

--
François Lafont



Re: Problème "basique" de scripting...

2017-09-08 Thread Raphaël POITEVIN
David BERCOT  writes:
> #!/bin/bash
>
> if [ -e "/etc/apt/sources.list.d/*" ]
> then

il manque un ; après le ]

>     rm /etc/apt/sources.list.d/*
> fi
-- 
Raphaël
Hypra S.A.S.



Problème "basique" de scripting...

2017-09-08 Thread David BERCOT
Bonjour,

Je viens de ré-installer mon système suite à un plantage et,
bizarrement, un script tout simple ne fonctionne plus correctement.
Malgré divers tests et recherches, j'avoue que  je ne comprends pas bien...

Le voici :
#!/bin/bash

if [ -e "/etc/apt/sources.list.d/*" ]
then
    rm /etc/apt/sources.list.d/*
fi

En doublant les crochets, ça ne change rien.
En supprimant les quotes, j'ai l'erreur suivante : ligne 3 : [: trop
d'arguments (que je ne comprends pas non plus d'ailleurs)...
J'ai bien des fichiers dans /etc/apt/sources.lists.d/ [je coupe court à
tout commentaire sur le sujet : ce n'est pas le problème ;-)] mais il
fait comme si ce n'était pas le cas.

Auriez-vous une piste ?

Merci d'avance.

David.



scripting soundcards in debian?

2015-11-25 Thread Karen Lewellen

Hi everyone,
i suspect that Larry's question might not have been articulated properly, 
so trying again.

he has four soundcards, and runs Debian from the console.
What he desires, if even technically possible,  is a way to insure an 
application will skip to the next unused soundcard, or perhaps to move the 
application there when his first one is in use.

He is mainly doing this while running ice weasel.
Thoughts?
Thanks,
Karen



Re: Bash Scripting Question

2013-11-07 Thread Chris Davies
Jonathan Dowland j...@debian.org wrote:
 On Sun, Nov 03, 2013 at 09:58:58PM +0100, Erwan David wrote:
 Maybe you'll need something like expect to handle this.

 I'd second expect, it's probably the best tool for the job in all
 non-trivial cases.

The empty-expect package, perhaps?
Chris


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/e2vskaxd2t@news.roaima.co.uk



Re: Bash Scripting Question

2013-11-05 Thread Zenaan Harkness
On 11/4/13, Thomas H. George li...@tomgeorge.info wrote:
 The script I am trying to write executes a program that requires a
 keyboard response. I have experimented with redirecting STDIN but haven't
 found the
 correct way to make the response.

To read a value (perhaps half your problem):

apt-cache show ...
zenity # gnome
kdialog # kde
xdialog # x generic
expect # Tk (not sure I understand expect)
dialog or whiptail #curses (text)

http://code.google.com/p/yad/ # xenity fork with many improvements

Good luck,
Zenaan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/caosgnsqrh+2g7issiazssiwhztskydovx459ubygf4frsru...@mail.gmail.com



Re: Bash Scripting Question

2013-11-04 Thread Jonathan Dowland
The tool 'yes' can be used to write an infinite stream of strings
(the default being 'y') to standard output, so if your program needed
only a sequence of a fixed string such as 'y', you could do

 yes | your-program

or 

 yes some-other-string | your-program

But if your program is not reading strictly from standard input (there
are other ways to get keyboard/interactive input), then…

On Sun, Nov 03, 2013 at 09:58:58PM +0100, Erwan David wrote:
 Maybe you'll need something like expect to handle this.

I'd second expect, it's probably the best tool for the job in all
non-trivial cases.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20131104100536.ga2...@bryant.redmars.org



Re: Bash Scripting Question

2013-11-04 Thread Karl E. Jorgensen
Hi

On Sun, Nov 03, 2013 at 02:35:30PM -0500, Thomas H. George wrote:
 The script I am trying to write executes a program that requires a
 keyboard response. I have experimented with redirecting STDIN but haven't 
 found the
 correct way to make the response.  I found one example that scanned the
 response from apt-get install  for the letter y and fed this back to
 install .  In my case I must respond with a word in answer to the
 programs question.

Well - if you're trying to script a command, have a closer look at the
man-page for the command in question: There may be ways of making the
command non-interactive: Then you don't have to give it any input at
all!

If you are trying to script the apt-get install command, check out
the --yes option and it's relatives.

Note that apt WILL ask if you're trying to do crazy stuff, e.g. like
removing essential packages.  Even the simpler questions are there to
give you a chance not to shoot yourself in the foot: If you script the
answers to them, your (metaphorical) foot is in danger...

 I'm sure this must be elementary but I have read large sections of
 BASH GUIDE FOR BEGINNERS and  AVANCED BASH-SCRIPTING GUIDE without
 finding a solution.  I would appreciate a little help or advice.

:-) Good - that's definitely worth reading.

-- 
Karl E. Jorgensen


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20131104121304.GA10450@hawking



Bash Scripting Question

2013-11-03 Thread Thomas H. George
The script I am trying to write executes a program that requires a
keyboard response. I have experimented with redirecting STDIN but haven't found 
the
correct way to make the response.  I found one example that scanned the
response from apt-get install  for the letter y and fed this back to
install .  In my case I must respond with a word in answer to the
programs question.

I'm sure this must be elementary but I have read large sections of
BASH GUIDE FOR BEGINNERS and  AVANCED BASH-SCRIPTING GUIDE without
finding a solution.  I would appreciate a little help or advice.

Tom


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20131103193530.ga22...@tomgeorge.info



Re: Bash Scripting Question

2013-11-03 Thread Cousin Stanley

 The script I am trying to write executes a program 
 that requires a keyboard response.
  

  A varaible can be set to a keyboard response
  using a  read  prompt  

read -e -p What do you need ? xVariable

echo $xVariable


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/l56bqj$62c$1...@dont-email.me



Re: Bash Scripting Question

2013-11-03 Thread Erwan David
Le 03/11/2013 20:35, Thomas H. George a écrit :
 The script I am trying to write executes a program that requires a
 keyboard response. I have experimented with redirecting STDIN but haven't 
 found the
 correct way to make the response.  I found one example that scanned the
 response from apt-get install  for the letter y and fed this back to
 install .  In my case I must respond with a word in answer to the
 programs question.

 I'm sure this must be elementary but I have read large sections of
 BASH GUIDE FOR BEGINNERS and  AVANCED BASH-SCRIPTING GUIDE without
 finding a solution.  I would appreciate a little help or advice.

 Tom



Maybe you'll need something like expect to handle this.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5276b912.1080...@rail.eu.org



variables en bash-scripting

2013-05-21 Thread Mariano Cediel
IP1=1 2 3 4
IPA=a b c

n=1
ip=IP$n

for x in ***ip***; do
 bla; bla
done

En lugar de ***ip*** yo ponia ${!ip} y funcionaba (al menos en el bash del
CENTOS), pero en debian7 no funciona
Y no sé cómo hacer la pregunta respectiva al google, de ahí esta consulta.

Una mano, por favor.

Saludos.

-- 

[o - -  -   --  -
   (\   |  u d t
   (  \_('  c c s
   (__(=_) s o ?
  -=


Re: variables en bash-scripting

2013-05-21 Thread fernando sainz
El día 21 de mayo de 2013 10:29, Mariano Cediel
mariano.ced...@gmail.com escribió:
 IP1=1 2 3 4
 IPA=a b c

 n=1
 ip=IP$n

 for x in ***ip***; do
  bla; bla
 done

 En lugar de ***ip*** yo ponia ${!ip} y funcionaba (al menos en el bash del
 CENTOS), pero en debian7 no funciona
 Y no sé cómo hacer la pregunta respectiva al google, de ahí esta consulta.

 Una mano, por favor.

 Saludos.


Pues funciona.
Seguro que usas bash?

$ P1=1 2 3 4
$ ip=IP1
$ for x in ${!ip}; do echo $x; done
1
2
3
4

S2


--
To UNSUBSCRIBE, email to debian-user-spanish-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAGw=rHi264Yûzngzzmhzbeabytwdy5q9po3svc5jm2zkj...@mail.gmail.com



Re: variables en bash-scripting

2013-05-21 Thread Camaleón
El Tue, 21 May 2013 10:29:13 +0200, Mariano Cediel escribió:

 IP1=1 2 3 4
 IPA=a b c
 
 n=1
 ip=IP$n
 
 for x in ***ip***; do
  bla; bla
 done
 
 En lugar de ***ip*** yo ponia ${!ip} y funcionaba (al menos en el bash
 del CENTOS), 

Pues en lenny lo ejecuta.

 pero en debian7 no funciona 

¿Qué error te saca?

 Y no sé cómo hacer la pregunta respectiva al google, de ahí esta
 consulta.

Supongo que buscaras por esto:

http://www.enricozini.org/2008/tips/bash-indirection/

Saludos,

-- 
Camaleón


-- 
To UNSUBSCRIBE, email to debian-user-spanish-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/kng1gh$1n2$8...@ger.gmane.org



Re: variables en bash-scripting [SOLUCIONADO]

2013-05-21 Thread Mariano Cediel
El 21 de mayo de 2013 16:48, Camaleón noela...@gmail.com escribió:

 El Tue, 21 May 2013 10:29:13 +0200, Mariano Cediel escribió:

  IP1=1 2 3 4
  IPA=a b c
 
  n=1
  ip=IP$n
 
  for x in ***ip***; do
   bla; bla
  done
 
  En lugar de ***ip*** yo ponia ${!ip} y funcionaba (al menos en el bash
  del CENTOS),

 Pues en lenny lo ejecuta.

  pero en debian7 no funciona

 ¿Qué error te saca?

  Y no sé cómo hacer la pregunta respectiva al google, de ahí esta
  consulta.

 Supongo que buscaras por esto:

 http://www.enricozini.org/2008/tips/bash-indirection/

 Saludos,

 --
 Camaleón


 --
 To UNSUBSCRIBE, email to debian-user-spanish-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/kng1gh$1n2$8...@ger.gmane.org



Error MIO

estaba debugando con sh -x script.sh
y además en la cabecera estaba poniendo #!/bin/sh

en lugar de #!/bin/bash

Saludos y gracias.

--

[o - -  -   --  -
   (\   |  u d t
   (  \_('  c c s
   (__(=_) s o ?
  -=


--
To UNSUBSCRIBE, email to debian-user-spanish-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/cab-01r6ftuhhn9mfalkfxxrfa5sohsp_baqwuy0ndpghrx5...@mail.gmail.com



scripting inherited commands user rights

2013-02-07 Thread Muhammad Yousuf Khan
i have got a /data folder where no one has rights accept user root.
and for some reasons or reducing my dependency i have created a script
which include
mkdir command

like this

mkdir /data/example

the script own by the user and have got rights 700 on the script file
so that only that specific user can run the script however when the
script ran it gives us this error
mkdir: cannot create directory `/data/example ': Permission denied

i dont want to give any user  -w , -r and -x rights on the folder but
what i want is that he can only create directory via that script only.


Thanks,


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAGWVfM=bzk_o98ugcaiqefhljht60vjz-d25_5sfpqkjzyz...@mail.gmail.com



Re: scripting inherited commands user rights

2013-02-07 Thread Alex Mestiashvili
On 02/07/2013 02:10 PM, Muhammad Yousuf Khan wrote:
 i have got a /data folder where no one has rights accept user root.
 and for some reasons or reducing my dependency i have created a script
 which include
 mkdir command
 
 like this
 
 mkdir /data/example
 
 the script own by the user and have got rights 700 on the script file
 so that only that specific user can run the script however when the
 script ran it gives us this error
 mkdir: cannot create directory `/data/example ': Permission denied
 
 i dont want to give any user  -w , -r and -x rights on the folder but
 what i want is that he can only create directory via that script only.
 
 
 Thanks,
 
 

you can use sudo to run a command with elevated rights.

Regards,
Alex


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5113b21f.2070...@biotec.tu-dresden.de



Re: scripting inherited commands user rights

2013-02-07 Thread Muhammad Yousuf Khan
Thanks for the hint i have been going through couple of howtos but it
is still not working same error i put this line at the bottom of the
VISUDO still no luck

%ykhan ALL = NOPASSWD: /usr/bin/myscript

when i run the script with user ykhan still give me the same error.

would you please be kind enough and share a good howto or guide by
example. that would be very helpful.

Thanks

On Thu, Feb 7, 2013 at 6:54 PM, Alex Mestiashvili
a...@biotec.tu-dresden.de wrote:
 On 02/07/2013 02:10 PM, Muhammad Yousuf Khan wrote:
 i have got a /data folder where no one has rights accept user root.
 and for some reasons or reducing my dependency i have created a script
 which include
 mkdir command

 like this

 mkdir /data/example

 the script own by the user and have got rights 700 on the script file
 so that only that specific user can run the script however when the
 script ran it gives us this error
 mkdir: cannot create directory `/data/example ': Permission denied

 i dont want to give any user  -w , -r and -x rights on the folder but
 what i want is that he can only create directory via that script only.


 Thanks,



 you can use sudo to run a command with elevated rights.

 Regards,
 Alex


 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/5113b21f.2070...@biotec.tu-dresden.de



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/cagwvfmn4k5m0mrxuc+ezvzd4ua2hy4nh5v7mb2+wc1cjeek...@mail.gmail.com



Re: scripting inherited commands user rights

2013-02-07 Thread Alex Mestiashvili
On 02/07/2013 03:54 PM, Muhammad Yousuf Khan wrote:
 Thanks for the hint i have been going through couple of howtos but it
 is still not working same error i put this line at the bottom of the
 VISUDO still no luck

 %ykhan ALL = NOPASSWD: /usr/bin/myscript

 when i run the script with user ykhan still give me the same error.

 would you please be kind enough and share a good howto or guide by
 example. that would be very helpful.

 Thanks

 On Thu, Feb 7, 2013 at 6:54 PM, Alex Mestiashvili
 a...@biotec.tu-dresden.de wrote:
   
 On 02/07/2013 02:10 PM, Muhammad Yousuf Khan wrote:
 
 i have got a /data folder where no one has rights accept user root.
 and for some reasons or reducing my dependency i have created a script
 which include
 mkdir command

 like this

 mkdir /data/example

 the script own by the user and have got rights 700 on the script file
 so that only that specific user can run the script however when the
 script ran it gives us this error
 mkdir: cannot create directory `/data/example ': Permission denied

 i dont want to give any user  -w , -r and -x rights on the folder but
 what i want is that he can only create directory via that script only.


 Thanks,


   
 you can use sudo to run a command with elevated rights.

 Regards,
 Alex


 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/5113b21f.2070...@biotec.tu-dresden.de

 

   
Please do not top-post [0]

the example you gave me looks correct, nevertheless :

cat /home/admin/myscript.sh
#!/bin/bash
mkdir /root/test

chmod 755 /home/admin/myscript.sh

just to be sure:
chmod 700 /root
chown root /root

cat /etc/sudoers | grep admin
admin   ALL = NOPASSWD: /home/admin/myscript.sh

as user admin
ls -l /root
ls: cannot open directory /root: Permission denied


 sudo ./myscript.sh  echo $?
0

one more time :

sudo ./myscript.sh  
mkdir: cannot create directory `/root/test': File exists

as root,
ls -l /root | grep test
drwxr-xr-x 2 root root4096 Feb  7 16:07 test


[0]
http://wiki.debian.org/FAQsFromDebianUser#What_is_top-posting_.28and_why_shouldn.27t_I_do_it.29.3F


Regards,
Alex


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5113c430.2080...@biotec.tu-dresden.de



Re: scripting inherited commands user rights

2013-02-07 Thread Linux-Fan
On 02/07/2013 03:54 PM, Muhammad Yousuf Khan wrote:
 Thanks for the hint i have been going through couple of howtos but it
 is still not working same error i put this line at the bottom of the
 VISUDO still no luck
 
 %ykhan ALL = NOPASSWD: /usr/bin/myscript
 
 when i run the script with user ykhan still give me the same error.

The user needs to run $ sudo /usr/bin/myscript to start the script as root.

 would you please be kind enough and share a good howto or guide by
 example. that would be very helpful.

I have in my sudoers (among others):

# Configure command to use (always use whole path here)
Cmnd_Alias  SHUTDOWN = /opt/ma/bin/mahalt
linux-fan   ALL=NOPASSWD: SHUTDOWN

Which allows linux-fan to use sudo /opt/ma/bin/mahalt to shut down the
computer. In order not to require the script to be run with sudo
explicitely, I have (in my script, I have not copied it but wrote it as
I remembered it so there might be typing errors in it)

if ! [ $(id -u) = 0 ]
then
exec sudo $0 $@
fi

Which re-starts the script with sudo if it is not run with root permissions.

 Thanks
 
 On Thu, Feb 7, 2013 at 6:54 PM, Alex Mestiashvili
 a...@biotec.tu-dresden.de wrote:
 On 02/07/2013 02:10 PM, Muhammad Yousuf Khan wrote:
 i have got a /data folder where no one has rights accept user root.
 and for some reasons or reducing my dependency i have created a script
 which include
 mkdir command

 like this

 mkdir /data/example

 the script own by the user and have got rights 700 on the script file
 so that only that specific user can run the script however when the
 script ran it gives us this error
 mkdir: cannot create directory `/data/example ': Permission denied

 i dont want to give any user  -w , -r and -x rights on the folder but
 what i want is that he can only create directory via that script only.


 Thanks,



 you can use sudo to run a command with elevated rights.

 Regards,
 Alex


 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/5113b21f.2070...@biotec.tu-dresden.de


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5113c41a.8030...@web.de



Re: scripting inherited commands user rights

2013-02-07 Thread Alex Mestiashvili
On 02/07/2013 03:54 PM, Muhammad Yousuf Khan wrote:
 Thanks for the hint i have been going through couple of howtos but it
 is still not working same error i put this line at the bottom of the
 VISUDO still no luck

 %ykhan ALL = NOPASSWD: /usr/bin/myscript
   

btw %ykhan -means members of group ykhan and not user ykhan ...

Alex


 when i run the script with user ykhan still give me the same error.

 would you please be kind enough and share a good howto or guide by
 example. that would be very helpful.

 Thanks

 On Thu, Feb 7, 2013 at 6:54 PM, Alex Mestiashvili
 a...@biotec.tu-dresden.de wrote:
   
 On 02/07/2013 02:10 PM, Muhammad Yousuf Khan wrote:
 
 i have got a /data folder where no one has rights accept user root.
 and for some reasons or reducing my dependency i have created a script
 which include
 mkdir command

 like this

 mkdir /data/example

 the script own by the user and have got rights 700 on the script file
 so that only that specific user can run the script however when the
 script ran it gives us this error
 mkdir: cannot create directory `/data/example ': Permission denied

 i dont want to give any user  -w , -r and -x rights on the folder but
 what i want is that he can only create directory via that script only.


 Thanks,


   
 you can use sudo to run a command with elevated rights.

 Regards,
 Alex


 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/5113b21f.2070...@biotec.tu-dresden.de

 

   


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5113c4e7.8020...@biotec.tu-dresden.de



Re: scripting inherited commands user rights

2013-02-07 Thread Muhammad Yousuf Khan
Thanks Alex and linux-Fan, this worked for me  :)


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAGWVfMnbgxHar3OzNrE=piqDCfbCTZr3=jhl43regwepnoe...@mail.gmail.com



Re: OT: A question about bash scripting

2012-10-30 Thread Chris Davies
Ralf Mardorf ralf.mard...@alice-dsl.net wrote:
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)

You've got a horrible race condition in there just waiting to bite
you. Try this instead:

done=$(date +%s)
month=$(date --date @$done +%B)
mon=$(date --date @$done +%b)
d_y_t=$(date --date @$done +'/%d/%Y %T')

Chris


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/7ud4m9xtms@news.roaima.co.uk



Re: OT: A question about bash scripting

2012-10-30 Thread Ralf Mardorf
On Tue, 30 Oct 2012 08:58:31 +0100, Chris Davies  
chris-use...@roaima.co.uk wrote:



done=$(date +%s)
month=$(date --date @$done +%B)
mon=$(date --date @$done +%b)
d_y_t=$(date --date @$done +'/%d/%Y %T')


I agree, good idea.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/op.wmzth9s8qhadp0@suse11-2



Re: OT: A question about bash scripting

2012-10-29 Thread Ralf Mardorf
On Mon, 2012-10-29 at 15:00 -0400, Wolf Halton wrote:
 On Mon, Oct 29, 2012 at 6:57 AM, Ralf Mardorf
 ralf.mard...@alice-dsl.net wrote:
  Hi :)
 
  how can I get rid of the variable seconds?
 
  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}
 ^^^ the math should replace the
  variable.
 
  ### Killall and Restore session
   started=$(date +%s)
   bash $song_path/session/start-session-$startversion
 
   ### Time
   month=$(date +%B)
   mon=$(date +%b)
   d_y_t=$(date '+/%d/%Y %T')
   done=$(date +%s)
   ((seconds=(done-started)-(((done-started)/60)*60)+100))
   min_sec=$(((done-started)/60)):${seconds: -2}
   echo
   echoAttended time to restore session: $min_sec
   echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
   echo
 
  TIA,
  Ralf
 
 
 
 Ralf,
 I don't understand.
 What are you wanting to do with the script?
 If you don't like the name of the variable, make up another one.
 
 Wolf

This part of a larger script is a stopwatch and I want the math
((done-started)-(((done-started)/60)*60)+100))   inside the formatted
string   ${seconds: -2}   , instead of a variable.

Something similar to
${((done-started)-(((done-started)/60)*60)+100)): -2}

Similar, because I'm missing something.

Regards,
Ralf

PS: In German:
Das ${seconds: -2} formatiert den String und statt seconds soll dort
((done-started)-(((done-started)/60)*60)+100)) eingefügt werden. Doch
wie?







-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1351538780.1119.14.camel@localhost.localdomain



Re: OT: A question about bash scripting

2012-10-29 Thread Neal Murphy
On Monday, October 29, 2012 03:26:20 PM Ralf Mardorf wrote:
 On Mon, 2012-10-29 at 15:00 -0400, Wolf Halton wrote:
  On Mon, Oct 29, 2012 at 6:57 AM, Ralf Mardorf
  
  ralf.mard...@alice-dsl.net wrote:
   Hi :)
   
   how can I get rid of the variable seconds?
   
   ((seconds=(done-started)-(((done-started)/60)*60)+100))
   min_sec=$(((done-started)/60)):${seconds: -2}
   
  ^^^ the math should replace the
   
   variable.
   
   ### Killall and Restore session
   
started=$(date +%s)
bash $song_path/session/start-session-$startversion

### Time
month=$(date +%B)
mon=$(date +%b)
d_y_t=$(date '+/%d/%Y %T')
done=$(date +%s)
((seconds=(done-started)-(((done-started)/60)*60)+100))
min_sec=$(((done-started)/60)):${seconds: -2}
echo
echoAttended time to restore session: $min_sec
echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
echo
   
   TIA,
   Ralf
  
  Ralf,
  I don't understand.
  What are you wanting to do with the script?
  If you don't like the name of the variable, make up another one.
  
  Wolf
 
 This part of a larger script is a stopwatch and I want the math
 ((done-started)-(((done-started)/60)*60)+100))   inside the formatted
 string   ${seconds: -2}   , instead of a variable.
 
 Something similar to
 ${((done-started)-(((done-started)/60)*60)+100)): -2}
 
 Similar, because I'm missing something.

You missed the $((...)) syntax as exemplified by the '(done-started)/60' just 
before it:
  min_sec=$(((done-started)/60)):
  min_sec=${min_sec}$(((done-started)-(((done-started)/60)*60)+100))



Re: OT: A question about bash scripting

2012-10-29 Thread Ralf Mardorf
On Mon, 2012-10-29 at 15:59 -0400, Neal Murphy wrote:
 On Monday, October 29, 2012 03:26:20 PM Ralf Mardorf wrote:
 
  On Mon, 2012-10-29 at 15:00 -0400, Wolf Halton wrote:
 
   On Mon, Oct 29, 2012 at 6:57 AM, Ralf Mardorf
 
   
 
   ralf.mard...@alice-dsl.net wrote:
 
Hi :)
 

 
how can I get rid of the variable seconds?
 

 
((seconds=(done-started)-(((done-started)/60)*60)+100))
 
min_sec=$(((done-started)/60)):${seconds: -2}
 

 
^^^ the math should replace the
 

 
variable.
 

 
### Killall and Restore session
 

 
started=$(date +%s)
 
bash $song_path/session/start-session-$startversion
 

 
### Time
 
month=$(date +%B)
 
mon=$(date +%b)
 
d_y_t=$(date '+/%d/%Y %T')
 
done=$(date +%s)
 
((seconds=(done-started)-(((done-started)/60)*60)+100))
 
min_sec=$(((done-started)/60)):${seconds: -2}
 
echo
 
echo Attended time to restore session: $min_sec
 
echo -n Session restored at  ; printf %9.9s $month ; echo
 $d_y_t
 
echo
 

 
TIA,
 
Ralf
 
   
 
   Ralf,
 
   I don't understand.
 
   What are you wanting to do with the script?
 
   If you don't like the name of the variable, make up another one.
 
   
 
   Wolf
 
  
 
  This part of a larger script is a stopwatch and I want the math
 
  ((done-started)-(((done-started)/60)*60)+100)) inside the formatted
 
  string ${seconds: -2} , instead of a variable.
 
  
 
  Something similar to
 
  ${((done-started)-(((done-started)/60)*60)+100)): -2}
 
  
 
  Similar, because I'm missing something.
 
  
 
 You missed the $((...)) syntax as exemplified by the
 '(done-started)/60' just before it:
 
 min_sec=$(((done-started)/60)):
 
 min_sec=${min_sec}$(((done-started)-(((done-started)/60)*60)+100))

I want

 ((seconds=(done-started)-(((done-started)/60)*60)+100))
 min_sec=$(((done-started)/60)):${seconds: -2}

in one line, instead of two lines.

I don't understand your reply.

Even if I would add ${min_sec: 2} to each echo command (there will be
a second output to a log file, it wouldn't be formatted as needed.

FOR YOUR EXAMPLE, IIUC IT SHOULD BE? ...

 ### Killall and Restore session
 started=$(date +%s)
 sleep 2
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 #((seconds=(done-started)-(((done-started)/60)*60)+100))
 #min_sec=$(((done-started)/60)):${seconds: -2}
 
min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60)+100))
 echo
 echoAttended time to restore session: $min_sec
 echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
 echo

... RESULT ...

Attended time to restore session: 0:102
Session restored at   October/29/2012 21:11:43

... RESP. ...

 ### Killall and Restore session
 started=$(date +%s)
 sleep 2
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 #((seconds=(done-started)-(((done-started)/60)*60)+100))
 #min_sec=$(((done-started)/60)):${seconds: -2}
 
min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60)+100))
 min_sec=${min_sec: 2}
 echo
 echoAttended time to restore session: $min_sec
 echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
 echo

... RESULT ...

Attended time to restore session: 102
Session restored at   October/29/2012 21:17:26

BUT I NEED ...

 ### Killall and Restore session
 started=$(date +%s)
 sleep 2
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 ((seconds=(done-started)-(((done-started)/60)*60)+100))
 min_sec=$(((done-started)/60)):${seconds: -2}
 echo
 echoAttended time to restore session: $min_sec
 echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
 echo

... THIS RESULT ...

Attended time to restore session: 0:02
Session restored at   October/29/2012 21:21:32

... WHILE I WONT THIS 2 lines, AS ONE LINE, INCLUDING THE FORMATTING:

 ((seconds=(done-started)-(((done-started)/60)*60)+100))
 min_sec=$(((done-started)/60)):${seconds: -2}

Regards,
Ralf


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1351542663.1119.40.camel@localhost.localdomain



Re: OT: A question about bash scripting

2012-10-29 Thread Ralf Mardorf

 ... WHILE I WONT THIS 2 lines, AS ONE LINE, INCLUDING THE FORMATTING:
Oops, an evil typo ;), it should be ... while I want. The capital
letters aren't for shouting, just to distinguish the mail's text from
the script.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1351543007.1119.44.camel@localhost.localdomain



Re: OT: A question about bash scripting

2012-10-29 Thread Dom

On 29/10/12 20:31, Ralf Mardorf wrote:
(trimmed)


I want

  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}

in one line, instead of two lines.

I don't understand your reply.

Even if I would add ${min_sec: 2} to each echo command (there will be
a second output to a log file, it wouldn't be formatted as needed.

FOR YOUR EXAMPLE, IIUC IT SHOULD BE? ...

  ### Killall and Restore session
  started=$(date +%s)
  sleep 2

  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  #((seconds=(done-started)-(((done-started)/60)*60)+100))
  #min_sec=$(((done-started)/60)):${seconds: -2}
  
min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60)+100))
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo

... RESULT ...

Attended time to restore session: 0:102
Session restored at   October/29/2012 21:11:43

... RESP. ...

  ### Killall and Restore session
  started=$(date +%s)
  sleep 2

  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  #((seconds=(done-started)-(((done-started)/60)*60)+100))
  #min_sec=$(((done-started)/60)):${seconds: -2}
  
min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60)+100))
  min_sec=${min_sec: 2}
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo

... RESULT ...

Attended time to restore session: 102
Session restored at   October/29/2012 21:17:26

BUT I NEED ...

  ### Killall and Restore session
  started=$(date +%s)
  sleep 2

  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo

... THIS RESULT ...

Attended time to restore session: 0:02
Session restored at   October/29/2012 21:21:32

... WHILE I WONT THIS 2 lines, AS ONE LINE, INCLUDING THE FORMATTING:

  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}



Would this do what you are after?

### Killall and Restore session
started=$(date +%s)
sleep 2

### Time
month=$(date +%B)
mon=$(date +%b)
d_y_t=$(date '+/%d/%Y %T')
done=$(date +%s)
echo
printf Attended time to restore session:  %4d:%02d\n 
$(((done-started)/60)) $(((done-started)%60))

printf Session restored at %9.9s%s\n $month $d_y_t
echo

(The first printf is a long line that will probably get spilt by 
email. It should all be on one line).


Also the SECONDS shell counter variable is useful for this sort of thing.

For example:
### Killall and Restore session
SECONDS=0

...

done=$SECONDS

--
Dom


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/508ef5cd.8070...@rpdom.net



Re: OT: A question about bash scripting

2012-10-29 Thread Neal Murphy
On Monday, October 29, 2012 04:31:03 PM Ralf Mardorf wrote:

 FOR YOUR EXAMPLE, IIUC IT SHOULD BE? ...
 
  ### Killall and Restore session
  started=$(date +%s)
  sleep 2
 
  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  #((seconds=(done-started)-(((done-started)/60)*60)+100))
  #min_sec=$(((done-started)/60)):${seconds: -2}
  min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60
 )+100)) echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo
 
 ... RESULT ...
 
 Attended time to restore session: 0:102
 Session restored at   October/29/2012 21:11:43
 
 ... RESP. ...
 
  ### Killall and Restore session
  started=$(date +%s)
  sleep 2
 
  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  #((seconds=(done-started)-(((done-started)/60)*60)+100))
  #min_sec=$(((done-started)/60)):${seconds: -2}
  min_sec=$(((done-started)/60)):$(((done-started)-(((done-started)/60)*60
 )+100)) min_sec=${min_sec: 2}
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo
 
 ... RESULT ...
 
 Attended time to restore session: 102
 Session restored at   October/29/2012 21:17:26
 
 BUT I NEED ...
 
  ### Killall and Restore session
  started=$(date +%s)
  sleep 2
 
  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo
 
 ... THIS RESULT ...
 
 Attended time to restore session: 0:02
 Session restored at   October/29/2012 21:21:32
 
 ... WHILE I WONT THIS 2 lines, AS ONE LINE, INCLUDING THE FORMATTING:
 
  ((seconds=(done-started)-(((done-started)/60)*60)+100))
  min_sec=$(((done-started)/60)):${seconds: -2}
 
 Regards,
 Ralf

What's the '+100' supposed to do? Add 100 to the remaining seconds? Or 
subtract 100 from it? (That is, increase or decrease the number of seconds?) 
The way it is now, the number of seconds will never be less than 100 and your 
': -2' tweak will never trigger anyway.

What you are asking cannot be done. You cannot nest substitutions in the 
manner you wish, and getting the leading zero on the seconds is problematic 
using only bash.

I don't think you can put that many conditionals on a single line and have it 
remain comprehendable.

However, you might be able to do it using awk:

  ### Killall and Restore session
  started=$(date +%s)
  sleep 2
 
  ### Time
  month=$(date +%B)
  mon=$(date +%b)
  d_y_t=$(date '+/%d/%Y %T')
  done=$(date +%s)
  min_sec=$(((done-started)/60)):$(echo $done $started | awk '{s=($1-$2)%60; 
if (s==0) {s=2;} printf (%2.2d, s);}')
  echo
  echoAttended time to restore session: $min_sec
  echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
  echo

But regardless, the line is going to be rather long. Unless you use a shell 
function:

getSeconds () {
  echo $done $started | \
awk '{
  s=($1-$2)%60;
  if (s==0) {s=2;}
  printf (%2.2d, s);
}'


Then use:
  min_sec=$(((done-started)/60)):$(getSeconds)

But I still don't see what the '+100 is supposed to do.


Re: OT: A question about bash scripting

2012-10-29 Thread Ralf Mardorf
On Mon, 2012-10-29 at 21:31 +, Dom wrote:
 Would this do what you are after?
 
 ### Killall and Restore session
 started=$(date +%s)
 sleep 2
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 echo
 printf Attended time to restore session:  %4d:%02d\n 
 $(((done-started)/60)) $(((done-started)%60))
 printf Session restored at %9.9s%s\n $month $d_y_t
 echo
 
 (The first printf is a long line that will probably get spilt by 
 email. It should all be on one line).
 
 Also the SECONDS shell counter variable is useful for this sort of thing.
 
 For example:
 ### Killall and Restore session
 SECONDS=0
 
 ...
 
 done=$SECONDS

Thank you :)

that's it.

 started=$(date +%s)
 SECONDS=0
 sleep 72
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 done_2=$SECONDS

 ((seconds=(done-started)-(((done-started)/60)*60)+100))
 min_sec=$(((done-started)/60)):${seconds: -2}
 echo
 echoAttended time to restore session: $min_sec
 echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
 echo

 ((min=(done_2/60))) ; ((sec=(done_2%60)))
 echo
 printf Attended time to restore session: %9d:%02d\n $min $sec
 printf Session restored at %9.9s%s\n $month $d_y_t
 echo

 ### Log file
 grep Write to log file enabled. $log_file  /dev/null
 if [ $? -eq 0 ] ; then
  echoRestore: $min_sec $mon$d_y_t $log_file
  printfRestore: %s:%02d %s%s\n $min $sec $mon $d_y_t  $log_file
 fi

Regards,
Ralf


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1351552967.1119.52.camel@localhost.localdomain



[sloved] OT: A question about bash scripting

2012-10-29 Thread Ralf Mardorf
On Mon, 2012-10-29 at 18:52 -0400, Neal Murphy wrote:
 What's the '+100' supposed to do?

 ### Killall and Restore session
 started=$(date +%s)
 SECONDS=0
 sleep 2
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 done_2=$SECONDS

 ((seconds=(done-started)-(((done-started)/60)*60)))
 seconds=0$seconds ### THIS EXPLAINS AND REPLACES THE +100
 min_sec=$(((done-started)/60)):${seconds: -2}
 echo
 echoAttended time to restore session: $min_sec
 echo -n Session restored at  ; printf %9.9s $month ; echo $d_y_t
 echo

 ### THIS IS WHAT I LIKE THE BEST
 ((min=(done_2/60))) ; ((sec=(done_2%60)))
 echo
 printf Attended time to restore session: %9d:%02d\n $min $sec
 printf Session restored at %9.9s%s\n $month $d_y_t
 echo

http://lists.debian.org/debian-user/2012/10/msg01286.html

Regards,
Ralf


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1351554170.1119.59.camel@localhost.localdomain



Re: Crontab, Scripting and Syslog (solved)

2012-07-04 Thread Titanus Eramius
On Mon, 2 Jul 2012 15:47:35 +0200
Titanus Eramius tita...@aptget.dk wrote:

 snip
 
  # min hr dom mon dow command 
   *   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21
  
  That is, every minute during hour 4, on every day of every month
  (that being every day of the week), the command is run.
  
  Presumably, webalizer writes its output to the same place each time,
  so that is why you're only seeing the output of the 4:59 run.
  
  Try changing your crontab to read:
  
  # min hr dom mon dow command 
0   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21
  
  This will run at 4:00 every day, and is probably what you meant.
  
 Yes it is.
 I'll try and set it and return tommorrow.
 
 Cheers
 
 

It works perfect. Thanks for the help :)

Cheers


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120704124712.6ea4b...@asrock.local.aptget.dk



Re: Crontab, Scripting and Syslog (solved)

2012-07-04 Thread Titanus Eramius
On Mon, 02 Jul 2012 15:07:46 +0100
Chris Davies chris-use...@roaima.co.uk wrote:

 Titanus Eramius tita...@aptget.dk wrote:
  * 04 * * * /home/titanus/scripts/web-log  /dev/null 21
 
  The line runs every morning at 4, and AFAIK, the /dev/-part should
  redirect all but errors to null.
 
 No.
 
 1. This runs every minute while the hour is 4. If you want the script
 to run only a 4am, you need to specify a zero minute value too
 
 2. The  /dev/null 21 tells cron to thow away not just errors but
 also all normal output. If you want to lose information written to
 stderr (typically errors), then you need 2 /dev/null
 
 0 4 * * * /home/titanus/scripts/web-log 2/dev/null
 
 Chris
 
 

Thank you for the corrections, the first part works now, and
the second part will probaly be tested by some future error.

Cheers


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120704125006.55639...@asrock.local.aptget.dk



Crontab, Scripting and Syslog

2012-07-02 Thread Titanus Eramius
Hi folks
On my webserver I've recently added a log-sorting and presentation
program by the name of Webalizer. To make it run, I've put this line in
the crontab (everything runs as a normal user):

* 04 * * * /home/titanus/scripts/web-log  /dev/null 21

The line runs every morning at 4, and AFAIK, the /dev/-part should
redirect all but errors to null.

The script is really simple:

#!/bin/sh
webalizer=/usr/bin/webalizer
yesterday_date=$(date -d yesterday +%Y.%m.%d)

# For debugging
# echo $webalizer
# echo $yesterday_date

if test -e /var/log/apache2/access.$yesterday_date; then
   $webalizer /var/log/apache2/access.$yesterday_date
   else
   echo Yesterdays log not found. Exiting
   exit 12
fi

exit 0

Now, my question is these lines in syslog:

titanus@aptget:~$ sudo cat /var/log/syslog | grep titanus
Jun 11 04:00:01 aptget /USR/SBIN/CRON[1567]: (titanus) CMD
(/home/titanus/scripts/web-log  /dev/null 21)
Jun 11 04:01:01 aptget /USR/SBIN/CRON[1572]: (titanus) CMD
(/home/titanus/scripts/web-log  /dev/null 21)

(One line per minut for an entire hour)

Jun 11 04:59:01 aptget /USR/SBIN/CRON[1879]: (titanus) CMD
(/home/titanus/scripts/web-log  /dev/null 21)

What do they mean?
As far as I can see, the result of Webalizer is made at 4, not 4:59, so
I suspect the srcipt only runs at 4. The system is a standard Squeeze
with nothing funny or unstable.

Thanks, tit


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120702145106.4aecd...@asrock.local.aptget.dk



Re: Crontab, Scripting and Syslog

2012-07-02 Thread Darac Marjal
On Mon, Jul 02, 2012 at 02:51:06PM +0200, Titanus Eramius wrote:
 Hi folks
 On my webserver I've recently added a log-sorting and presentation
 program by the name of Webalizer. To make it run, I've put this line in
 the crontab (everything runs as a normal user):
 
 * 04 * * * /home/titanus/scripts/web-log  /dev/null 21
 
 The line runs every morning at 4, and AFAIK, the /dev/-part should
 redirect all but errors to null.
 
 The script is really simple:
 
[cut]
 
 Now, my question is these lines in syslog:
 
 titanus@aptget:~$ sudo cat /var/log/syslog | grep titanus
 Jun 11 04:00:01 aptget /USR/SBIN/CRON[1567]: (titanus) CMD
 (/home/titanus/scripts/web-log  /dev/null 21)
 Jun 11 04:01:01 aptget /USR/SBIN/CRON[1572]: (titanus) CMD
 (/home/titanus/scripts/web-log  /dev/null 21)
 
 (One line per minut for an entire hour)
 
 Jun 11 04:59:01 aptget /USR/SBIN/CRON[1879]: (titanus) CMD
 (/home/titanus/scripts/web-log  /dev/null 21)
 
 What do they mean?
 As far as I can see, the result of Webalizer is made at 4, not 4:59, so
 I suspect the srcipt only runs at 4. The system is a standard Squeeze
 with nothing funny or unstable.

These lines are cron telling you what it's running. Note that your
crontab line states: 

# min hr dom mon dow command 
 *   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21

That is, every minute during hour 4, on every day of every month (that
being every day of the week), the command is run.

Presumably, webalizer writes its output to the same place each time, so
that is why you're only seeing the output of the 4:59 run.

Try changing your crontab to read:

# min hr dom mon dow command 
  0   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21

This will run at 4:00 every day, and is probably what you meant.



signature.asc
Description: Digital signature


Re: Crontab, Scripting and Syslog

2012-07-02 Thread Titanus Eramius
snip

 # min hr dom mon dow command 
  *   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21
 
 That is, every minute during hour 4, on every day of every month (that
 being every day of the week), the command is run.
 
 Presumably, webalizer writes its output to the same place each time,
 so that is why you're only seeing the output of the 4:59 run.
 
 Try changing your crontab to read:
 
 # min hr dom mon dow command 
   0   04 *   *   *   /home/titanus/scripts/web-log  /dev/null 21
 
 This will run at 4:00 every day, and is probably what you meant.
 
Yes it is.
I'll try and set it and return tommorrow.

Cheers


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120702154735.1ecfc...@asrock.local.aptget.dk



Re: Crontab, Scripting and Syslog

2012-07-02 Thread Chris Davies
Titanus Eramius tita...@aptget.dk wrote:
 * 04 * * * /home/titanus/scripts/web-log  /dev/null 21

 The line runs every morning at 4, and AFAIK, the /dev/-part should
 redirect all but errors to null.

No.

1. This runs every minute while the hour is 4. If you want the script
to run only a 4am, you need to specify a zero minute value too

2. The  /dev/null 21 tells cron to thow away not just errors but
also all normal output. If you want to lose information written to stderr
(typically errors), then you need 2 /dev/null

0 4 * * * /home/titanus/scripts/web-log 2/dev/null

Chris


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/iim8c9x3dg@news.roaima.co.uk



Scripting question

2012-04-17 Thread Chris
All 

Firstly I petty much suck at scripting so I need help.

I have a file where each line begins with

Smtp:

I would like have the Smtp: replaced with To:  leaving all that follows in each 
line untouched and piped into a new file.

Thanks!!
Chris

Re: Scripting question

2012-04-17 Thread Eduardo M KALINOWSKI

On Ter, 17 Abr 2012, Chris wrote:

Firstly I petty much suck at scripting so I need help.

I have a file where each line begins with

Smtp:

I would like have the Smtp: replaced with To:  leaving all that  
follows in each line untouched and piped into a new file.


man sed


--
The majority of husbands remind me of an orangutang trying to play the violin.
-- Honor'e DeBalzac

Eduardo M KALINOWSKI
edua...@kalinowski.com.br




--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: 
http://lists.debian.org/20120417105220.horde.5niuduisjlfpjxwuaiyv...@mail.kalinowski.com.br



Re: Scripting question

2012-04-17 Thread emmanuel segura
perl -e 'while(){chomp; s/root/Root/g; print  $_\n; }' /etc/passwd



Il giorno 17 aprile 2012 15:52, Eduardo M KALINOWSKI 
edua...@kalinowski.com.br ha scritto:

 On Ter, 17 Abr 2012, Chris wrote:

 Firstly I petty much suck at scripting so I need help.

 I have a file where each line begins with

 Smtp:

 I would like have the Smtp: replaced with To:  leaving all that follows
 in each line untouched and piped into a new file.


 man sed


 --
 The majority of husbands remind me of an orangutang trying to play the
 violin.
-- Honor' e DeBalzac

 Eduardo M KALINOWSKI
 edua...@kalinowski.com.br




 --
 To UNSUBSCRIBE, email to debian-user-REQUEST@lists.**debian.orgwith a
 subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/**20120417105220.Horde.**
 5niudUisJlFPjXWUaIYVfNA@mail.**kalinowski.com.brhttp://lists.debian.org/20120417105220.horde.5niuduisjlfpjxwuaiyv...@mail.kalinowski.com.br




-- 
esta es mi vida e me la vivo hasta que dios quiera


Re: Scripting question

2012-04-17 Thread Daniel Landau
On Tue, Apr 17, 2012 at 4:52 PM, Eduardo M KALINOWSKI
edua...@kalinowski.com.br wrote:
 On Ter, 17 Abr 2012, Chris wrote:
 I would like have the Smtp: replaced with To:  leaving all that follows in
 each line untouched and piped into a new file.

 man sed


Read that too, but try also searching online for sed tutorial. The
line to do this specific thing is:

$ sed -e 's/^Smtp:/To:/' oldfile  newfile

Daniel Landau


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/CAPBTYu4KBgb55tjHHXysWed=+s2=kDnSECYNT1i=h1jowm9...@mail.gmail.com



Re: scripting question: to parse data with varname=value pattern the easiest way?

2010-11-02 Thread Zhang Weiwu, Beijing
 On 11/02/2010 05:04 AM, Karl Vogel wrote:
On the other hand, if someone sneaks something like
result_04: dc=3 rm /something/valuable
Thank you! very informative, and, kinda fun to read.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4ccff56c.90...@realss.com



scripting question: to parse data with varname=value pattern the easiest way?

2010-11-01 Thread Zhang Weiwu
 Hello.

A program output is like this:

result_01: a=23 b=288 c=A_string ac=34
result_02: a=23 b=28 c=A_string_too dc=3



I am writing a script to output values of b if b is in the result set.

It would be rather easy to match value of with regular expression:

/b=([^]*)/ # \1 would be the value of b.

Out of curiosity I just wonder is there an alternative way? One came to
my mind is to replace result_* with an invoke of awk, then the
name=value pattern become parameter of awk, then I can simply do '{print
$b;}' to get value of b. I tried that without success.



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4cce70ed.7050...@realss.com



Re: scripting question: to parse data with varname=value pattern the easiest way?

2010-11-01 Thread Karl Vogel
 On Mon, 01 Nov 2010 15:49:01 +0800, 
 Zhang Weiwu zhangwe...@realss.com said:

Z A program output is like this:
Z   result_01: a=23 b=288 c=A_string ac=34
Z   result_02: a=23 b=28 c=A_string_too dc=3
Z   

Z I am writing a script to output values of b if b is in the result set.

   If your data is trustworthy and follows shell assignment rules like the
   example above, you can abuse sh/ksh/bash:

 #!/bin/bash

 sample='result_01: a=23 b=288 c=A_string ac=34
 result_02: a=23 c=A_string_too dc=3
 result_03: a=23 b=28 c=A_string_too dc=3'

 echo $sample | while read str
 do
 unset b   # or whatever you're looking for
 set $str  # will fail horribly if $str is empty
 result=$1
 shift
 eval $@
 test $b  echo $result $b
 done
 exit 0

   On the other hand, if someone sneaks something like
   result_04: dc=3 rm /something/valuable

   into your program output, you'll get a nasty surprise.

-- 
Karl Vogel  I don't speak for the USAF or my company

Most users (myself included) spend most of their time in front of a computer
in a kind of fuzzy autopilot mode, and anything that creates ripples on that
placid lake of unawareness is going to be noticed as a disproportionately
significant problem. --David Harris, creator of Pegasus Mail


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101101210436.50fccb...@kev.msw.wpafb.af.mil



Re: Scripting gnome-panels

2010-05-20 Thread Mickey Fox
2010/5/19 Eric Persson e...@persson.tm:
 I have a small bashscript which prepares a dual-monitor setup for my laptop,
 since i'm moving in and out of the office and meetings, I tend to attach and
 disconnect the monitor a few times a day.

 That works fine with xrandr, but the issue is that I would like some gnome
 panels to move, and add one to the extra monitor. I have googled around but
 cant seemt o find that it would be possible, but it must be in some way, us
 usual. So, any hints?

 Basically, add one panel to one monitor, and add a window list to that
 panel.

 Best regards,
  Eric


 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject
 of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/4bf38357.3090...@persson.tm



Just some hints to you. You man configure one and only panel. Then run
the command:
gconftool -R /apps/panel  one_panel

Then add another panel and configure it as you will. Then run gconftool again:
gconftool -R /apps/panel  two_panels

Maybe all the differences are that between file one_panel and
two_panel. Then you can use command gconftool for scripting.
I am not sure whether it works. You may try it.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/aanlktikjveo4rjkeagpkafzntlcmf3napwtwtlva6...@mail.gmail.com



Scripting gnome-panels

2010-05-19 Thread Eric Persson
I have a small bashscript which prepares a dual-monitor setup for my 
laptop, since i'm moving in and out of the office and meetings, I tend 
to attach and disconnect the monitor a few times a day.


That works fine with xrandr, but the issue is that I would like some 
gnome panels to move, and add one to the extra monitor. I have googled 
around but cant seemt o find that it would be possible, but it must be 
in some way, us usual. So, any hints?


Basically, add one panel to one monitor, and add a window list to that 
panel.


Best regards,
  Eric


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4bf38357.3090...@persson.tm



una de bash scripting..

2010-05-03 Thread anso -
Estic segur de que es tracta de una tonteria, però no aconsegueixo
resoldre-ho!

tinc un script que te una durada determinada (uns 4 minuts) i m'agradaria
fer algun tipus de control sobre l'execució per tal que si passessin 6
minuts s'acabés la execució.

Que hauria de fer? se m'ha acudit crear un procés fill que executi un sleep
260 i després un kill, però ni se si en bash es poden fer processos fill ni
m'acaba de agradar la idea...

Oi que hi ha algun mètode mes simple?

Gracies


Re: una de bash scripting..

2010-05-03 Thread Matthias Kaehlcke
El Mon, May 03, 2010 at 08:28:00PM +0200 anso - ha dit:

Estic segur de que es tracta de una tonteria, pero no aconsegueixo
resoldre-ho!
tinc un script que te una durada determinada (uns 4 minuts) i m'agradaria
fer algun tipus de control sobre l'execucio per tal que si passessin 6
minuts s'acabes la execucio.
Que hauria de fer? se m'ha acudit crear un proces fill que executi un
sleep 260 i despres un kill, pero ni se si en bash es poden
fer processos fill ni m'acaba de agradar la idea...
Oi que hi ha algun metode mes simple?

aptitude install timeout :)

-- 
Matthias Kaehlcke
Embedded Linux Developer
Barcelona

You can chain me, you can torture me, you can even
  destroy this body, but you will never imprison my mind
(Mahatma Gandhi)
 .''`.
using free software / Debian GNU/Linux | http://debian.org  : :'  :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4  `-


-- 
To UNSUBSCRIBE, email to debian-user-catalan-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100503182926.gq3...@darwin



Re: una de bash scripting..

2010-05-03 Thread Parra
podries mirar de comparar l'hora d'inici del procés amb l'hora actual.
L'hora d'inici del procés la pots saber amb la comanda ps aux, que té una
columna anomenada START que és l'hora d'inici. Si el procés que dura 4
minuts és un bucle o és iteratiu pots executar la comparació en una
subshell.

De totes maneres ha d'haver una forma més bona de controlar-ho, potser per
l'estat del procés, però ara mateix no se m'acudeix res.

Sort!




2010/5/3 anso - ansobeg...@gmail.com

 Estic segur de que es tracta de una tonteria, però no aconsegueixo
 resoldre-ho!

 tinc un script que te una durada determinada (uns 4 minuts) i m'agradaria
 fer algun tipus de control sobre l'execució per tal que si passessin 6
 minuts s'acabés la execució.

 Que hauria de fer? se m'ha acudit crear un procés fill que executi un
 sleep 260 i després un kill, però ni se si en bash es poden
 fer processos fill ni m'acaba de agradar la idea...

 Oi que hi ha algun mètode mes simple?

 Gracies



Re: una de bash scripting..

2010-05-03 Thread anso -
Perfecte! gracies a tots!

Timeout no el puc instalar a la maquina on el puc executar, simplement no ho
tinc permès...

el primer manual era una mica avançat per a mi, però finalment amb l'exemple
del marc he trobat la sol·lució! gracies a tots!

P.D. No coneixia el us de $$, suposo que significa el proces pare, no?

El 3 de maig de 2010 20:57, marc.ol...@grupblau.com ha escrit:


 Bones,

 Si que es poden fer threads, n'hi ha prou en posar un  despres de la
 comanda o funció, o embolcallar les instruccions amb (). Si t'agrada o
 no, ja és cosa teva ;-)

 Aquest script funciona:

 - talla -
 #!/bin/sh

 (
#Això és el threat
sleep 5
kill -15 $$
 )

 for i in 1 2 3 4 5 6 7 8 9
 do
echo $i
sleep 1
 done

 exit
 -

 Salut!

 On Mon, 3 May 2010 20:28:00 +0200, anso - ansobeg...@gmail.com wrote:
  Estic segur de que es tracta de una tonteria, però no aconsegueixo
  resoldre-ho!
 
  tinc un script que te una durada determinada (uns 4 minuts) i
 m'agradaria
  fer algun tipus de control sobre l'execució per tal que si passessin 6
  minuts s'acabés la execució.
 
  Que hauria de fer? se m'ha acudit crear un procés fill que executi un
  sleep
  260 i després un kill, però ni se si en bash es poden fer processos
 fill
  ni
  m'acaba de agradar la idea...
 
  Oi que hi ha algun mètode mes simple?
 
  Gracies

 --
 Marc Olivé
 Grup Blau



Re: una de bash scripting..

2010-05-03 Thread marc.olive

Bones,

Si que es poden fer threads, n'hi ha prou en posar un  despres de la
comanda o funció, o embolcallar les instruccions amb (). Si t'agrada o
no, ja és cosa teva ;-)

Aquest script funciona:

- talla -
#!/bin/sh

(
#Això és el threat
sleep 5
kill -15 $$
)

for i in 1 2 3 4 5 6 7 8 9
do
echo $i
sleep 1
done

exit
-

Salut!

On Mon, 3 May 2010 20:28:00 +0200, anso - ansobeg...@gmail.com wrote:
 Estic segur de que es tracta de una tonteria, però no aconsegueixo
 resoldre-ho!
 
 tinc un script que te una durada determinada (uns 4 minuts) i
m'agradaria
 fer algun tipus de control sobre l'execució per tal que si passessin 6
 minuts s'acabés la execució.
 
 Que hauria de fer? se m'ha acudit crear un procés fill que executi un
 sleep
 260 i després un kill, però ni se si en bash es poden fer processos
fill
 ni
 m'acaba de agradar la idea...
 
 Oi que hi ha algun mètode mes simple?
 
 Gracies

--
Marc Olivé
Grup Blau


-- 
To UNSUBSCRIBE, email to debian-user-catalan-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/963a29493f113bc853a28f41b42d2...@blauconsultors.com



Re: una de bash scripting..

2010-05-03 Thread marc.olive

$$ és el PID (identificador del procés) de l'script, si. Crec que també
es pot usar $BASHPID, però sempre he usat $$, és més curt i criptic i el
jefe veu que soc cool, jejeje, a mes, /bin/sh que especifica l'script
no te pq ser bash, així que no em fio de $BASHPID.

De res!

On Mon, 3 May 2010 21:04:14 +0200, anso - ansobeg...@gmail.com wrote:
 Perfecte! gracies a tots!
 
 Timeout no el puc instalar a la maquina on el puc executar, simplement
no
 ho
 tinc permès...
 
 el primer manual era una mica avançat per a mi, però finalment amb
 l'exemple
 del marc he trobat la sol·lució! gracies a tots!
 
 P.D. No coneixia el us de $$, suposo que significa el proces pare, no?
 
 El 3 de maig de 2010 20:57, marc.ol...@grupblau.com ha escrit:
 

 Bones,

 Si que es poden fer threads, n'hi ha prou en posar un  despres de la
 comanda o funció, o embolcallar les instruccions amb (). Si t'agrada
o
 no, ja és cosa teva ;-)

 Aquest script funciona:

 - talla -
 #!/bin/sh

 (
#Això és el threat
sleep 5
kill -15 $$
 )

 for i in 1 2 3 4 5 6 7 8 9
 do
echo $i
sleep 1
 done

 exit
 -

 Salut!

 On Mon, 3 May 2010 20:28:00 +0200, anso - ansobeg...@gmail.com wrote:
  Estic segur de que es tracta de una tonteria, però no aconsegueixo
  resoldre-ho!
 
  tinc un script que te una durada determinada (uns 4 minuts) i
 m'agradaria
  fer algun tipus de control sobre l'execució per tal que si passessin
6
  minuts s'acabés la execució.
 
  Que hauria de fer? se m'ha acudit crear un procés fill que executi un
  sleep
  260 i després un kill, però ni se si en bash es poden fer processos
 fill
  ni
  m'acaba de agradar la idea...
 
  Oi que hi ha algun mètode mes simple?
 
  Gracies

 --
 Marc Olivé
 Grup Blau



-- 
To UNSUBSCRIBE, email to debian-user-catalan-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/4db3707337206ce34522e4f5e27d9...@blauconsultors.com



Re: bash scripting question

2010-03-29 Thread Josep M.
Hello.

I found these somewhere time ago. check if is what You need:





function timer()
{
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local  stime=$1
etime=$(date '+%s')

if [[ -z $stime ]]; then stime=$etime; fi

dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
printf '%d:%02d:%02d' $dh $dm $ds
fi
}

 
This is before the command

t=$(timer)

and this is after the command

printf 'Elapsed time: %s\n' $(timer $t)



example

t=$(timer)

copy /dev/null /dev/zero

printf 'Elapsed time: %s\n' $(timer $t)



Greetings
Josep

El vie, 19-03-2010 a las 10:19 -0700, Mike McClain escribió:
 I've written a function to print elapsed time similar to /usr/bin/time
 but can be called at the beginning and end of a script from within
 the script. Occasionally I get an error: '8-08: value too great for base'
 It's caused by the difference in these 2 command strings but I can't for 
 the life of me see what's going on.
 
 now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 
 09
 
 str=09; str=${str#*0}; echo $str; 
 9
 
 Thanks,
 Mike
 -- 
 Satisfied user of Linux since 1997.
 O ascii ribbon campaign - stop html mail - www.asciiribbon.org
 
 



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1269865700.29265.2.ca...@mail.navegants.net



  1   2   3   4   5   6   7   >