How to redirect output of cu to a file ? - linux

I am using cu utility to connect my Cubieboard 1 with my laptop. As I boot my Cubieboard , it sends the boot log to my terminal.
What I want is that the output should be displayed to my screen as well as be sent to some log file which I specify.
I can't find any option to do the same. Any ideas on how I could do that ?

Alternatively, if standard error should be in the file
<command> 2>&1 | tee log.txt
or
<command> |& log.txt

You could pipe into tee. You should then see output on screen and logged to a file of your choice.
<command> | tee log.txt

Related

I want not to save the logs that are "warning" in the log crontab

I want not to save the logs that are "warning" in the log file that the crontab creates, I only want the "error" messages, does anyone know how I can exclude these messages?
I have tried doing a grep -v but it doesn't work:
45 5 * * * /home/username/barc/backupsql.sh 2>&1 | grep -v 'Warning: Using a password on the command line interface can be insecure.'
Thanks in advance for anyone trying to help me.
Crontab lets you execute 1 scheduled command/script at a time.
Piping the output of your script to Grep command won't work. Furthermore, crontab by default redirects output to dev/null, therefore you won't see the output unless you save it to a file.
I suggest something like this:
Edit your script to redirect it's output to a file with your grep command. For example by adding
DATE=$(date +"%m_%d_%Y")
some command | grep -v Warning >> /tmp/$DATE.log # Here
Edit your Cron job to execute the script every day like you did, removing everything after the pipe:
45 5 * * * /home/username/barc/backupsql.sh
In order to monitor the output you could use tail command as follows:
tail -f /tmp/$DATE.log

bash redirect output to file but result is incomplete

The question of redirecting output of a command was already asked many times, however I am having a strange behavior. I am using a bash shell (debian) with version
4.3.30(1)-release and tried to redirect output to a file, however not everything are logged in the file.
The bin file that I tries to run is sauce-connectv4.4.1 for linux (client of saucelabs that is publicly available in internet)
If I run
#sudo ./bin/sc --doctor
it showed me a complete lines
it prints :
INFO: resolved to '23.42.27.27'
INFO: resolving 'g2.symcb.com' using
DNS server '10.0.0.5'...
(followed by other line)
INFO: 'google.com' is not in hosts file
INFO: URL https://google.com can be reached
However, if I redirect the same command to a file with the following command
#sudo ./bin/sc --doctor > alloutput.txt 2>&1
and do
#cat alloutput.txt
the same command output is logged, but deprecated as following:
INFO: resolved to '23.42.2me#mymachine:/opt/$
It has incomplete line, and the next lines that follows are not even logged (missing).
I have tried with >> for appending, it has the same problem. Using command &> alloutput.txt also is not printing the whole stuff. Can anyone point out how to get all lines of the above command to be logged completely to the text file?
UPDATE
In the end I manage to use the native binary logging by using --log
alloutput.txt where it completely provide me with the correct output.
However I let this issue open as I am still wondering why one misses some information/lines by doing an output redirection
you should try this: stdbuf -o0
like:
stdbuf -o0 ./bin/sc --doctor 2>&1 | tee -a alloutput.txt
That is a funny problem, I've never seen that happening before. I am going to go out on a limb here and suggest this, see how it works:
sudo ./bin/sc --doctor 2>&1 | tee -a alloutput.txt
#commandtorun &> alloutput.txt
This command will redirects both the error and output to same file.

Piping To Grep Is Giving Too Many Results

I'm trying to check whether a particular service is running via a Linux terminal, and the following command doesn't seem to be filtering the results as expected. Not sure what I'm doing wrong...
service --status-all | grep subversion
This produces several lines of output, including, for example,
[ ? ] Networking
I'm not sure why this is happening, since the string "subversion" is not contained within the above line...
You should use:
service --status-all |& grep subversion
Because the services without a status ([ ? ]) are sent to stderr, which is not pipelined to grep (and then it is printed on your terminal regardless).
|& sends stderr to stdout so grep is able to filter it.
Try this and redirect stderr (2) to stdout (1):
service --status-all 2>&1 | grep subversion

issue with tee command and a script

im trying to use tee command with rendercheck tests on ubuntu 15.04, tee command works fine with 6 tests of rendercheck for example :
./rendercheck -t fill,dcoords,scoords,mcoords,tscoords,tmcoords | tee summary
but if i added other more , example :
./rendercheck -t fill,dcoords,scoords,mcoords,tscoords,tmcoords,composite | tee summary
the output does not shows in terminal and the file summary does not contain nothing, so im not sure why i have this behavior with tee command, it would be great if someone can help me, thanks
"composite" test opens a graphic window, doesn't display text to standard output.
I guess you'll obtain the same behavior if you just execute:
rendercheck composite | tee summary
Regards

Redirect output of Whatsapp bash script to file interactively for automation purpose

Yowsup-cli is a library that can allow you to send message to whatsapp users,once authenticated.
By the coommand
yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config
I can interactively send or receive messages.
Once executed the command you get a prompt like
MY_PHONE_NUMBER#s.whatsapp.net [27-12-2014 18:33]:THIS IS MY MESSAGE,TYPED ON MY PHONE. OPEN DOOR GARAGE
Enter Message or command: (/available, /lastseen, /unavailable)
I'm a totally beginner, but I would like to redirect this content that gets printed on terminal to a file,to further analyze it or to write a script that search into this file keyword as "OPEN GARAGE DOOR", so i could automate something.
This file obviously has to sync with the program output,but I don't know how to do.
yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config > /path/to/my_file
doesn't work
Running Ubuntu 12.04.
I know yowsup is a python library, but i don't know this language. I'm beginning learniing C and I would like to do that in BASH, or if not possible in C.
Thanks
Pipe the output into tee instead of redirecting it into a file:
yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config 2>&1 | tee -a /path/to/my_file
The reason: With redirection you don't see the command's output which makes interacting with it hard.
Piping into the tee command will echo all output the the terminal and append it to given file.
Interestingly, in your command line (using redirection) you can still type blindly or even according to the yowsup-cli ouptut you read in another terminal with:
tail -f /path/to/my_file
Tail with the -f option prints the last 10 lines of the file as well as any new ouptut from the yowsup-cli command.

Resources