log in ifup

I have a little script in the /etc/network/if-up.d (debian). It should do something and write the output to a log file. But it doesn't seem to work.

ifup wlan0 dosomething >> /var/log/dosomething.log

I would like to add the date to the output, can somebody help me please?
Thanks!

What does "doesn't seem to work" mean? What does happen? What do you want to happen?

date +"%Y-%m-%d_%H:%M:%S $(ifup wlan0 dosomething)" >> /var/log/dosomething.log

Hey, thanks for your help!

With your line, it just writes the date into the log file. No output of my dosomething program.

I tested my program; it works:

  • This writes the output of my program to the standard output (the terminal)
    text dosomething
  • This writes it to the log file
    text dosomething >> /var/log/dosomething.log
  • This writes it correctly to the standard output
    text date +"%Y-%m-%d_%H:%M:%S $(dosomething)"
  • This writes just the date (%Y-%m-%d_%H:%M:%S) to the log file (running as a script in /etc/network/if-up.d)
    text date +"%Y-%m-%d_%H:%M:%S $(ifup wlan0 dosomething)" >> /var/log/dosomething.log
    I don't know if my program was running.

Any idea?

date=$( date +"%Y-%m-%d_%H:%M:%S" )
something=$(dosomething)
if [ -z "$something" ] 
then
   echo "dosomething produced no output" >&2
   exit 1
fi
printf "%s %s\n" "$date" "$something" >> /var/log/dosomething.log

Thanks but why ifup wlan0 doesn't work?

What does "doesn't work" mean?

What does happen?

What, exactly, did you try?

Well, when the connection to the wlan is there I would expect that my program is running. The program works and gives output but it looks like not with ifup.