Programming :: Add Logging To Shell Scripts?
Jan 1, 2010
I have some simple shell scripts that perform backups and I was wondering how do I add logging? More specifically writing to a log file if any part of the script fails. An example of what my shell scripts look like:
[code]...
View 4 Replies
ADVERTISEMENT
May 29, 2011
I want a script to get executedutomatically whenever I login.Code is simple:Quote:dateYEs! it prints the date on the screen.I read somewhere that there is login.sh shell script which get executed automatically whenever one opens console.But how to insert the above code into it.?Also, we can put our command in $HOME/.bashrc and it will get executed everytime I start the interactive shell.
View 1 Replies
View Related
Oct 8, 2015
Some days ago (2015-09-28) I installed Debian testing amd64. Log in as a user failed and instead of the Gnome UI there was a sad face with the text: „Oh no! Something has gone wrong. A problem occurred and the system can't recover.
All extensions have been disabled as a precaution. Log out“.
The relevant output of journalctl (run as root) said:
etc/gdm3/Xsession[5379]: cannot connect to brltty at :0
- /etc/gdm3/Xsession[5379]: Service 'org.kde.kaccessibleapp' does not exist.
- gnome-session[5379]: x-session-manager[5379]: WARNING: Application 'gnome-shell.desktop' killed by signal 5
- gnome-session[5379]: x-session-manager[5379]: WARNING: App 'gnome-shell.desktop' respawning too quickly
- x-session-manager[5379]: Unrecoverable failure in required component gnome-shell.desktop
[Code] ...
After some investigating, I found three work-arounds.
(1) Use gdm3-autologin: In /etc/gdm3/daemon.conf, remove the double crosses and insert own user name
AutomaticLoginEnable = true
AutomaticLogin = <own user name>
Disadvantage: Only one user can have access to the Gnome ui. If you log out, you enter the gdm3 greeter and … see above.
(2) Turn off gdm3 by running 'systemctl stop gdm3' as root, log in into a terminal as a user and run startx.
(3) Install package lightdm and make it to the standard display manager with 'dpkg-reconfigure lightdm'.
Disadvantage: Energy manager and screensaver settings of the Gnome control center are ignored.
The easiest way, however, especially if there are several users, is logging in via the gdm3 greeter.
View 10 Replies
View Related
Dec 15, 2010
Is there an easy way to prevent the logging of commands run into syslog as post-shell expansion?
I.e log a command of "ls *.log" as just that, rather than "ls a.log b.log c.log d.log" It makes rather a mess of the log files.
View 1 Replies
View Related
Jun 5, 2011
I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.
Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....
View 10 Replies
View Related
Jun 25, 2010
Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?
Example:
Code:
>>> import subprocess
>>> help(subprocess)
...
[pages of stuff to read]
...
I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.
View 4 Replies
View Related
Mar 9, 2010
I tried to create a user on Solaris 10 but when I try to login the user with "su -" I get the error message "no directory". When I try to login with "su" I get the error message "no shell".
I tried the useradd several combinations e.g.
All the tries i made didn't work. I also checked the permissions on /etc, /bin, /sbin and / and it seems ok so that the newly created user can access them.
View 14 Replies
View Related
Sep 29, 2010
I'm deleting logs after they are backed up. The line below in a script is doing it but I'd like to print the list of files that are deleted into a log file. I tried printf at the end but can't seem to get it to work. I'm not sure how to output that at the end of the string. Also I was looking at man find man and the difference btween -exec and -execdir. I don't understand what it's saying. Is -execdir executing rm m within the /opt/temp/logs directory the difference?
View 4 Replies
View Related
Dec 15, 2009
I've created a simple script based menu. This menu will be accessed by only a certain users via ssh.When user logs in, the menu will automatically run. (configured at user's .bash_profile).How do I force the session to close when user hits Ctrl-C or Ctrl-Break ?In a nutshell, I don't want user to have access to shell.
View 11 Replies
View Related
May 21, 2011
I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files). I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin. If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :
adashiu_at_virtual_machine_name >
after that user can start to use commands reserved only for user mode. Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him. changing prompt and separated commands for user and admin ?
View 8 Replies
View Related
Jul 17, 2010
It is possible to check who logged in with "who" command. If we are also logged in to that linux pc.
But, is there any possibility to check without our login?(not even by ssh)
Our logging in to find that pc, will be wasting the cpu resources. And may disturb the user who is working on the x-session.
View 7 Replies
View Related
Apr 14, 2011
I've written an Expect script that assists with change management on Cisco devices. The script creates log files for pre-change, the change itself, and post-change. Each log and its commands is triggered by a ! command. For example:
Code:
./dochange.exp hostname
<script spawns bash, user SSHes to hostname>
!PRE
[code]....
All of this works fine. My big hair-pulling hiccup is that the resulting log files are filled with raw backspace characters! I am using log_file to log the output from the script. I stop and restart logging with a new file when needed. However, the log files are pretty much unusable. After doing some research, it looks like log_file sends output to the file in real-time, unbuffered. When I hit a key, it's immediately sent to the log. What I would like is for only the resulting string to go to the log. If I start to type 'reload' and instead type 'show run', I don't want 'reload' to be listed in the log at all.
View 1 Replies
View Related
Feb 10, 2009
My friend has a website whereby once you have logged in on one page, you are redirected to another page, with a url similar to:
[URL]
the random string changes each time you log in, however the login page has a static url What i was attempting to do is run a script to get some data from the members page (after uve logged in) - however ive been having some trouble in how to do this, as the variable url with the random string will become invalid after a certain time, and i did not want to consantly change it.
While reading through some documentation i read that wget should be able to login to a form login website however ive had no luck, the command i was attempting to use was:
wget --user USERNAME -password PASSWORD [URL]
similarly i also tried
wget --post-data "username=USERNAME&password=PASSWORD" [URL]
and even both combined. However neither has worked as the html dl'd is simply the login page website. I cannot post a direct link to the website as it is private, however ive looked at the source coding and ive extracted (what i think) is the relevant bit, which is:
Code:
<form action="/cgi-bin/sblogin/login.cgi" method="post" name="login" id="login"><br /><br />
<div class="user_text"><span class="text3">USERNAME:</span></div><div class="user_box"><input type="text" class="text" name="uname"></div>
[code].....
View 1 Replies
View Related
Jan 21, 2011
I recently started shell programming and my task now is to do a menu display.Currently i am stuck whereby user will input both title and author and it will delete it.
Do i have to use sed command?
View 4 Replies
View Related
May 17, 2010
Is it possible to assist in the programming Shell Scripts
Job:
To send a message to the email,All orders written in Terminal or ssh
example : ls , pwd , cat , and other
View 1 Replies
View Related
Feb 4, 2011
I have a situation where I am in a non-interactive shell. I have tried from within my non-interative shell to spawn an interactive shell but my output still does not goto me. Isn't there a way I can somehow go into /proc or somwhere and make the output my /dev/tty1? Or some way else to remedy this?The situation arises because I drop from my restricted shell environment (a sort of CLI interface), into the actual Linux shell. I cannot change the code of the CLI environment I am just faced with being in the linux shell environment and its non-interactive. Its very annoying to have to put > /dev/tty1 after every command I type.
Not to mention it seems damn near impossible to get pagers like more and less to work properly when your in a non-interactive shell.
View 2 Replies
View Related
Jul 13, 2011
I have a syslog-ng running and kernel build of 2.6.34.8 I use a syslog API in my program with facility LOG_LOCAL5 and and levels debug err and crit and info. when I ran on the older syslog facility I had everything logged fine as I intended. now I have written these rules into the syslog-ng.conf:
options {
flush_lines (0);
time_reopen (10);
log_fifo_size (1000);
[code]....
the last two rules show my program gnssapp. the result is all debug levels or crit or err levels I don't see any of them !
View 3 Replies
View Related
Dec 10, 2008
I have a shell script that I would like to log to stdout and also to a file.....much like using tee. I would like to, instead of calling the script and piping to tee...i would like for the script to tee itself.
View 4 Replies
View Related
Jul 11, 2010
i got to build my own linux shell for my project
View 5 Replies
View Related
Jul 23, 2010
I have been searching most of today and am stuck on getting a variable into an awk portion of my bash script. I have this working:
Code:
#!/bin/sh
SRC=/var/log/mail.log
DEST=/var/www/output/myFile.txt
VAR=userName@myDomain.tld
[code]....
Can awk take a shell variable? Or do I have to do something completely different?
View 11 Replies
View Related
Apr 2, 2011
I need to push out a file to a bunch of linux and solaris boxes so I was hoping to use a script to automate the process with scp (or something else / better) - how can I batchmode scp so that it will do this? I should mention the servers do have keys set up so I do not have to authenticate manually or through something like an expect script...
View 4 Replies
View Related
Feb 16, 2010
I am having a shell script with following lines
ORIG_LOG_ARCHIVE_FORMAT=`grep log_archive_format $LOG_DIR/init$CLONE_DB.ora | cut -d"=" -f2`
SRC_LOG_ARCHIVE_FORMAT=`sqlplus -s "/ as sysdba" @$SCRIPTS_DIR/log_archive_format.sql`
echo $ORIG_LOG_ARCHIVE_FORMAT
[code]...
When I execute this script I am getting below output
'enin16_%t_%s_%r.arc'
enip131_%t_%s_%r.arc
sed: command garbled: s/'enin16_%t_%s_%r.arc'/
However when I do the exact above command on unix prompt (refer below) after setting values for all variables, it is not giving sed garbled error message. May I know what should I do to make it work inside the script as well?
$ cat init_refresh$CLONE_DB.ora | sed "s/$ORIG_LOG_ARCHIVE_FORMAT/$SRC_LOG_ARCHIVE_FORMAT/g" > $LOG_DIR/init_refresh1$CLONE_DB.ora
$
View 3 Replies
View Related
Mar 24, 2011
I'm trying to write a toy linux shell. For starters this is what I'm trying to do:
1. Start a new process with fork.
2. Execute a program in the new process with execl().
3. Redirect the output from the new process from STDOUT to another file descriptor, using dup2(2).
4. In the parent process, read the output from the child process and write it to the screen.
Creating a new process and executing a program in it is no problems, the problem is that I can't seem to capture the output from it in the parent process.
Code:
//digenv
//C++arl 2011-03-24
#include <stdio.h>
#include <sys/types.h>
[code]...
View 14 Replies
View Related
Sep 6, 2013
How to use shell command?
installs.sh:
Code: Select allapt-get install icedove-l10n-hu
apt-get install rar
apt-get install ...
...
y press key or other language is other key. hungarian key is: i
english after apt-get install in gnome-terminal: (y)es or (n)o
hungarian after apt-get install in gnome-terminal: (i)gen or (n)em
How to yes or no automatically in all languages? Not manual, not 'Y'/'I' or 'N'/'N' keydown.
I would like use this script my fresh installed Debian 7.1. I would like run this install.sh when Debian is installed for my all softwares when i would like use.
10 PC installing easy and faster my script.
If no script is slowly install for my 10 PC.
View 2 Replies
View Related
Apr 2, 2010
I would like to know if there is any way to detect a command if it going to be executed in the shell?
Eg:
Cmd: sudo apt-get clean I want a C program to be called before this cmd is executed.
View 8 Replies
View Related
May 10, 2010
Im having problems with this little thing in a C example Im doing. I want to show in the shell like this example:
Name Birthday
Tomas 13
Adrian 24
Nate 15
Im trying to use the printf function but the names doesnt have the same lenght. So I cant do it like this:
printf("Name Bithday
");
printf("%s %d
");
View 4 Replies
View Related
Jul 12, 2010
I'm running into a problem when I try to set a variable to an awk output in c-shell. Right now my command is Code: set STR_MSG_TYPE = `awk -F{ '/msg_type/ {print $2}' <filename> | tr -d }'/''*' ` I then run echo to see what the output is and it returns blank, however, when I run the same awk command from the command line, I get an actual output of "MT-715". Am I setting my variable incorrectly? I do something similar using the date command to set a STR_DATE variable earlier in the code and it works fine and I use the same syntax.
View 1 Replies
View Related
Nov 22, 2010
I want to spawn a GDB session from bash script and keep it working to interact it from outside. But when I start it in background (with '&' sigil).
Code: gdb -x gdb_script.txt ./a.out < gdb_pipe.fifo &
It executes passed script and terminates by itself (I do not pass any data or signals to it)
Code: Breakpoint 33, main (argc=1, argv=0xbffff0f4) at main.c:53
---Type <return> to continue, or q <return> to quit---53
read_main_config();
(gdb) quit
A debugging session is active.
Inferior 1 [process 5957] will be killed.
Quit anyway? (y or n) [answered Y; input not from terminal] What can I do to make it alive?
View 1 Replies
View Related
Nov 26, 2010
I am aware this has probably been covered hundreds of times, so apologies if so. I am fairly new to the linux scripting scene, so again apologies if what I'm saying seems pretty odd and makes no sense. I am attempting to write a script for some Linux Fedora test servers I have set up. For me to change which domain I have this set to point to, I would have previously changed the HOSTS and profile files manually, however I managed to make a script which changes these easily with the use of one command to launch the script.The problem I'm having is getting it to use the "export" command. I am aware this would have to be launched in the parent shell rather than the child and so I made a seperate script which has "export SIP_DOMAIN="test.blah.net" in it and had the first script "source" it. This doesn't work and I've probably done something somewhere that is incredibly stupid.
View 2 Replies
View Related
Apr 28, 2011
I am very new to shell script, and my requirement is --
1. open the apache access log, use "cut" and "grep" to find the numbers.
2.put the result in a file
3.then compare the same result with day before result
4. send the result via e-mail.
so how can i do that , using some functions..
View 1 Replies
View Related