0

I am trying to log something in the console, but it doesn't work. The output is:

Resolving...
+ /keyboard
+ /keyboard/windows.keylayout
+ /keyboard/hardware.txt
Addition count 3 src: 60.42KB
 61868 / 61868 [====================================================] 100.00% 0s

I want that into a .log file.

But it only takes "Resolving...", when I execute "script >> script.log" as the first line, I guess that's because of the "+", how can I fix that, that it will log ALL of the output into that file?

cd /home/andre/test/ && /usr/local/bin/drive_armv7 pull -no-prompt keyboard 2>&1 >> error.log

Thanks.

André
  • 351
  • 1
  • 5
  • 19
  • Is all this output going into stdout? Or is some stuff getting written to stderr? – arjabbar Oct 05 '17 at 13:10
  • I don't actually know, how do I find that out? – André Oct 05 '17 at 13:13
  • It's possible that some of that output is going to `stderr` instead of `stdout`. `>>` by itself only redirects `stdout`. Possibly a dupe of https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash. – larsks Oct 05 '17 at 13:13
  • Possible duplicate of [How can I redirect and append both stdout and stderr to a file with Bash?](https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash) – larsks Oct 05 '17 at 13:13
  • I tired 2>&1 and it isn't working either... – André Oct 05 '17 at 13:14
  • Have tried the variations described here? https://askubuntu.com/questions/420981/how-do-i-save-terminal-output-to-a-file – arjabbar Oct 05 '17 at 13:15
  • yes I did, doesn't help either. Is is possible that it is buffered, because those messages in the console are displayed a bit delayed, so maybe >> only takes the immediate messages? – André Oct 05 '17 at 13:17
  • What exactly is the script doing? – Raman Sailopal Oct 05 '17 at 13:19
  • it is a google drive script that fetches data and downloads it. The files that are downloaded are displayed in the shell. – André Oct 05 '17 at 13:20
  • If the script explicitly writes to your `tty` there is no simple way to redirect that. You can run it under a pseudo-tty with something like Expect, maybe google for that. – tripleee Oct 05 '17 at 23:29

2 Answers2

1

Order of assignment?

cd /home/andre/test/ && /usr/local/bin/drive_armv7 pull -no-prompt keyboard 2>&1 >> error.log

tells stderr to go where stdout is going, which is the terminal. THEN you tell stdout to go into the log. Switch them -

cd /home/andre/test/ &&
/usr/local/bin/drive_armv7 pull -no-prompt keyboard >> error.log 2>&1  

That tells stdout to go into the log, THEN tells stderr to go where stdout is going...which is now the log.

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
  • andre@raspberrypi:~/test $ cat error.log Resolving... andre@raspberrypi:~/test $ The same problem, that wasn't the issue... – André Oct 05 '17 at 14:24
  • Need to see the actual execution. I assume you're using `set -x` somewhere in a loop to get those leading plus signs? Could we see some of the code, or at least something structurally identical? – Paul Hodges Oct 05 '17 at 14:59
0

It could be that you are running a default program called script

user@apollo:~$ script test
Script started, file is test

user@apollo:~$ which script
/usr/bin/script

If "script" is a local executable called "script.sh", you should run it as following

./script.sh

Trying to reproduce your issue gives no unexpected output

cat > script.sh <<EOF
echo "Resolving..."
echo "+ /keyboard"
echo "+ /keyboard/windows.keylayout"
echo "+ /keyboard/hardware.txt"
echo "Addition count 3 src: 60.42KB"
echo "61868 / 61868 [====================================================] 100.00% 0s"
EOF
chmod +x script.sh
./script.sh >> script.log
cat script.log

The unexpected behaviour depends on what your script is trying to do

Hakim K
  • 1
  • 4
  • is it possible that the script somehow does EOF in it so it stops writing into into the log file? If yes is there anything I can do to just ignore that and simply track the output of the terminal? – André Oct 05 '17 at 13:46
  • Also when I use a cronjob for that, it also just tells me "Resolving..." in the mail, I get as a result... What could that problem be? – André Oct 05 '17 at 13:50
  • EOF was just a Bash Here document example. If you edit your original question with the content of your script its much easier to help you debug :) – Hakim K Oct 05 '17 at 13:51