Programming :: How To Redirect Inside Bash Script
Oct 23, 2010
I want to do the following redirectin inside a bash script :
1. all the stdout will be redirected to a /tmp/log
2. all the errors will go to the stderr and also to the /tmp/log.
The following inside a bash script is not working, WHY and HOW to do it:
Rest of the bash script.
View 4 Replies
ADVERTISEMENT
Mar 9, 2011
I am trying to grep multiple numbers from file, grep does have the -f option for that.
Code: grep -f <`seq 500 520` /etc/passwd I know this could be done with
Code: for i in `seq 500 520`; do grep "$i" /etc/passwd; done But my question is fare more behind this example. It is possible to redirect one command output which will be treat as a content of file for another command ?
View 2 Replies
View Related
May 4, 2011
im pretty sure this is a remedial task for many of you but im having an issue with arrays from a shell script being accessed in an awk command. im pretty good with shell scripting but i am embarrassingly unfamiliar with awk. so here's the meat of the script...
Code:
I am trying to take an input file of ip addresses and corresponding netmasks and put it into a format to be loaded onto a juniper switch. the result should look something like this.. x.x.x.x/netmask using the cidr notation. no matter what subnet is provided though, /32 always gets appended to the end of the ip even when it should be /16, /24, etc... also, the cisco part works fine so that doesnt need any attention.
View 5 Replies
View Related
Feb 11, 2010
I have got a script with an outer and inner loop. The inner loop issues loads of echo's which need to be redirected to a log file determined by the outer loop. The obvious solution is to redirect every echo to >$LOG and set LOG in the outer loop.
Code:
for f in $FILES ; do
LOG=<logfile>
for l in $LINES ; do
[code]....
it is possible to map stdout to $LOG in the outer loop without having to redirect every subsequent individual command output?
View 4 Replies
View Related
Apr 2, 2010
What I'm trying to do is grep [mysqld] from inside my.cnf and then add lines inside the file should they not be there. how do i do that?
View 3 Replies
View Related
Feb 16, 2011
Writing script to create backup of file by adding datetime to file name. Basically test for file presence if there, cp with datetime then rm original cp works fine from command line but get cannot stat `full path to file': No such file or directory
Code:
Here are the errors: cp: cannot stat `~/html/CVP_dadamail/.dada_files/.logs/errors.txt': No such file or directory rm: cannot remove `...': No such file or directory
The for statement is a placeholder as I have same file to backup out of several directories. using "bash -x scriptname" -OR- inserting echos, I can see I've constructed the strings properly. Believing it might be related to the hidden directories, I tried setting the shopt "glob" options to no avail.
Ultimately I'll add the other directories to the for loop and then run this from a cron job, so if you see potential pitfalls knowing I'm headed in that direction...believe construct would be
Code:
View 4 Replies
View Related
Jan 24, 2011
I'm trying to create an SSL certificate and answer the questions inside a bash script. The command used to create the SSL certificate
Code: openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem
The first question asked is. Country Name (2 letter code) [AU]:
View 4 Replies
View Related
Jun 27, 2011
I have a set of bash scripts that I'm running that automatically build a set of packages for me and redirect their output into logs. Basically, I have a bunch of lines that are something like this: ${CONFIGURE_DIR}/configure &> ${LOG_DIR}/log or cd ${CONFIGURE_DIR} && make &> ${LOG_DIR}/log, etc.
This is supposed to make the entire process silent. However, sometimes with some packages some output leaks to my console (either stdout or stderr). I'm thinking that maybe the configure scripts/make are executing commands within new shell instances that don't inherit my redirect, or something to that effect.
Another reason for thinking this is that in another part of my script I detect errors when running make by testing with "if [ $? -ne 0 ]", and if the redirect leaks to my console and also the leaked output indicates that the build failed ("make: Error" and so on), then my $? test fails (i.e., it thinks that $? == 0, whereas a failed make should return a non-zero value). It's as if my original script can't "see" the results from child commands executed from later scripts.
View 1 Replies
View Related
Aug 26, 2010
I am writing a script in which I am using AWK to append to a line in a file and save the file. The command I am using is:
Code:
awk '{s=$0; if ( NR==4 ){s=s ":/usr/java/jdk1.6.0_19/bin" } print s;}' $appName > $appName.new
[code]...
View 4 Replies
View Related
Apr 28, 2011
I've noticed something, and hoped there was a work around.when I write a simple bash script, and run it, if I close the terminal i ran the bash script inside, the bash script stops. What are the solutions for this? Basically I want to run my bash script and close the terminal, keep the bash script running.
View 6 Replies
View Related
Jun 3, 2010
if I'm posting to the wrong forum. Be so kind to tell me where to better ask this question, as I'm really not finding the right words to google for.So, I have a shell application (fdb) which is a Flash debugger. I want to run it using bash script, capture it's output and pass it the commands (it can read from STDIN). The reason I want to do so is that Flash Builder (the IDE for Flash development) is plain stupid when it comes to compilation, and it won't allow me to compile any file in the project... so, I found out that I can make Eclipse to run an external tool. This external tool is my *.sh file whichches the compiler, and then it launches the debugger.The Eclipse console can display the compilation results, or errors. When I run the debugger it can even pass the input from Eclipse console to the debugger, however, the output from the debugger isn't shown.
View 1 Replies
View Related
Jun 8, 2011
I have trouble with using an alias inside aash function. I would like to ssh into multiple machines by executing:ssh machine To achieve this, I put something like the following into my ~/.bashrc:
alias machine='user@machine'
ssh()
{
[code]....
View 1 Replies
View Related
Dec 30, 2010
how do i use bash shell scripts inside php.I am just trying to call a simple cp command using php. Its not doing anything.
View 2 Replies
View Related
May 5, 2011
I'm trying create script to manage one mysql database, including new db and user creation. But I'm not able get it working when I put SQL commands into function. So I create simple script for testing which is still not working
Code:
#!/bin/bash -x
MAIN_DIR="/admin/mysql"
MYSQL_CNF="$MAIN_DIR/auth.cnf"
MYSQL_CMD="mysql --defaults-file=$MYSQL_CNF"
[code]....
View 1 Replies
View Related
Jan 28, 2010
I know that using alias I can run a whole command with a shortcut. But my requirement is to use parts of a long command and in between I have to pass some user defined values.
E.g. Suppose I have to routinely copy a directory to another remote directory on a remote machine.The remote machine name is quite long as well as the directory path to which I want to copy the files into.So the command to do scp would look like this[URL]Now I want to do some sort of aliasing (say "ecp") so that I just need to pass the source_directory name and the ecp command and do my job
View 3 Replies
View Related
Jul 12, 2010
I have this script in the past for csh: Code: ./a.out |& tee prints.txt which will redirect all printfs in the C program to the prints.txt file and at the same time show them in the console. How do you do this in bash? I have seen this, [URL] but it does not work for my bash and sh shells. It says:
Code: -bash: syntax error near unexpected token `&' and
Code: -sh: syntax error: unexpected "&"
View 2 Replies
View Related
Dec 9, 2010
I'm having problems with bash quoting. Maybe someone can tell me what's going on.. Basically, I need to create a command line inside a bash script that contains arguments that contain spaces and bash variables that need to be expanded.
[Code]...
View 5 Replies
View Related
Jan 23, 2010
I am attempting to write a backup script that will do the following:
1) lock and flush tables on a mysql db
2) dump the db to a file
3) unlock the tables
4) rsync the file to offsite storage
It all seems to be going well. However, obviously I don't want to setup ssh to the storage server on another network as the root user without a password. so I am attempting to su as the backup user inside of the script but when I try to run the script everything happens as it should until I try to so.. then it jumps out of the script .. akss me to login as the backup user.. proceeds to rsync to the offsite storage it does all this and then resumes execiting the script. it is not going to be setup as a cron job. it will be executed manually. assuming that is the case, how can I get the script to run without prompting for a password?
Here is what I've come up with so far... assuming that the script is run as root and the identity of the backup user will need to be assumed inside the script without perstering the user to enter the backup user's password.
[Code]....
View 8 Replies
View Related
Apr 20, 2010
Does unistd.h declare functions in the kernel or in the stdclib? Or in any other C file. I need to know from the inside how some of the functions work.
So where does unistd redirect to?
View 4 Replies
View Related
Jun 4, 2010
My hardware is the FriendlyArm mini2440 Samsung board. I run our main application from init.d/rcS. It uses printf's to display continuous program debug information that can be seen on the serial ttySAC2 console. I would like to be able to remotely view this information by a telnet connection when needed. What is the best way to accomplish this? The telnet user can possibly activate some script or program. I saw there is a ttysnoop program that I could not get to compile.
There must be a simpler way. There must be several ways. Instead of using printf I could do something else. I do not want to use a normal log file to the flash file system. I had thought of using a ram file in /var directory but it would complicate matters as I would need to limit its size and the telnet user needs to view the program's printfs in a real time fashion.
View 1 Replies
View Related
Aug 6, 2010
I am again struggling to make a script work, but hey, it is fun, I am learning new things. I discovered the set -x option which was, for me, like the second coming. Still, what I am not able to do is redirect ALL output to a (log) file, including what is produced by the -x setting. Let's assume a very simple script:
Code: #!/bin/bash
set -x
source="/home/atelier/Bureau/"
ls -la $source and I am running it as . test.sh >> /var/log/test.rmcb.log
The result of ls goes inded into the log file, but the rest still shows on the console where I am running the script: Code: ++ source=/home/atelier/Bureau/
++ ls --color=auto -la /home/atelier/Bureau/ Is there a way to redirect EVERYTHING to the log file ?
View 3 Replies
View Related
Nov 12, 2010
I feel kind of embarrassed posting here, but this is technically a scripting sub-forum. Here is the problem. I have a folder with various files which include .txt files as well
How can i redirect same content to each of the .txt files in the folder?
I have tried
Code: $ echo "hello" > *.txt
-bash: !": event not found Code: also cat ~/otherdir/test.txt > *.txt
-bash: *.txt: ambiguous redirect Can anyone help me with this?Ok i solved it
Code: #! /bin/bash
for file in *.txt
do
echo "Text that needs to be written" > $file
done
View 2 Replies
View Related
Jun 12, 2011
I have this code in PHP that is hosted on an nginx server.
Code:
I can download the files but the problem is I think nginx is treating it as a text file and changes all "0x0A" to "0x0D 0x0A"
Unfortunately the files are not text files but executable files which makes the downloaded file corrupted.
Do I need to add a specific header to prevent this from happening?
View 1 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
Apr 8, 2011
Is is possible to use a class inside a struct? I keep getting segmentation fault with this code:
Code:
struct my_struct {
unsigned count;
std::string msg;
[code]....
View 3 Replies
View Related
Jan 8, 2010
i have only basic knowledge of C so guys plz help me...is C language support call the C executable inside the C ?example contect mainA.c have a many function define in the struct,when i compile mainA and make a executable the name is ( A ),can i use executable C inside the C <my C program call the executable ( A ) > .
View 9 Replies
View Related
Apr 13, 2011
I want to read content of a file inside a gawk script.I know that by using "gawk -f filename" I can read a file, but I want to do that inside the script.
View 7 Replies
View Related
Feb 2, 2011
Basically I have a dir that contains my makefile and another directory inside this called source this holds main source files. External to these I have a couple of dirs common and drives.
In my make file I use
To include the protoypes from the headers in the folders common and drivers used by source, this works fine. However in common and drivers I use a few variables that are set in the source dir. I set these with externs inside the common and driver files. However I'm sure I should be able to set the directory path for source inside my makefile. So say I have inside source hardware.h with prototypes, I set DINCDIR = -I/Source -I../Drivers -I../CommonFiles
Then from a c file inside my common folder I say #include "hardware.h" the file should be able to see hardware.h and it's protoypes. However I get:
Is there some way I can get the extern dirs to see the source dir?
The set out is something like;
View 1 Replies
View Related
Feb 2, 2010
I am developing a script for the first time.
I am calling a script B.sh from A.sh
What if B.sh fails to run...how to go about it...
View 3 Replies
View Related
Feb 4, 2011
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
View 3 Replies
View Related