Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

output to log file bash

#!/bin/bash
echo "This logs to where I want, but using echo" > /var/log/mycustomlog

OR

#!/bin/bash
echo "I will just append to my custom log file" >> /var/log/customlog
Comment

logging output in bash scripts

#!/bin/bash

STATUSFILE=x.out
LOGFILE=x.log

### All output to screen
### Do nothing, this is the default


### All Output to one file, nothing to the screen
#exec > ${LOGFILE} 2>&1


### All output to one file and all output to the screen
#exec > >(tee ${LOGFILE}) 2>&1


### All output to one file, STDOUT to the screen
#exec > >(tee -a ${LOGFILE}) 2> >(tee -a ${LOGFILE} >/dev/null)


### All output to one file, STDERR to the screen
### Note you need both of these lines for this to work
#exec 3>&1
#exec > >(tee -a ${LOGFILE} >/dev/null) 2> >(tee -a ${LOGFILE} >&3)


### STDOUT to STATUSFILE, stderr to LOGFILE, nothing to the screen
#exec > ${STATUSFILE} 2>${LOGFILE}


### STDOUT to STATUSFILE, stderr to LOGFILE and all output to the screen
#exec > >(tee ${STATUSFILE}) 2> >(tee ${LOGFILE} >&2)


### STDOUT to STATUSFILE and screen, STDERR to LOGFILE
#exec > >(tee ${STATUSFILE}) 2>${LOGFILE}


### STDOUT to STATUSFILE, STDERR to LOGFILE and screen
#exec > ${STATUSFILE} 2> >(tee ${LOGFILE} >&2)


echo "This is a test"
ls -l sdgshgswogswghthb_this_file_will_not_exist_so_we_get_output_to_stderr_aronkjegralhfaff
ls -l ${0}
Comment

PREVIOUS NEXT
Code Example
Shell :: install kubectl on ubuntu 20 
Shell :: how to create an alias in bash 
Shell :: adobe flash player linux 
Shell :: create github repository 
Shell :: linux record camera 
Shell :: copy files from another branch git 
Shell :: append string to end of file name bash 
Shell :: git hub set up 
Shell :: how to chnage kubectl to k 
Shell :: how to install virtualmin on ubuntu 20.04 
Shell :: homestead change php version 
Shell :: tkPDFViewer install 
Shell :: how to sync my directory with my deleted file change 
Shell :: download stardocks sdk from nuget package 
Shell :: ubuntu video duplicate finder 
Shell :: tcp traffic analysis linux command line mb per second 
Php :: Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled 
Php :: how to make a php info 
Php :: print beauty php 
Php :: wordpress get template url 
Php :: Module php7.4 does not exist! 
Php :: how to get file extension in laravel 
Php :: deactivate woocommerce breadcrumbs 
Php :: php time a script 
Php :: laravel command to create symlink storage 
Php :: rewrite .php to no extension 
Php :: Composer detected issues in your platform: Your Composer dependencies require a PHP version "= 7.3.0". You are running 7.2.34 
Php :: inrandomorder laravel 
Php :: base64 encode laravel 
Php :: laravel turn off timestamps 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =