w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Status of perl scripts run from bash scripts
Perl scripts behave the same when run from the shell. Having test.pl: #!/usr/bin/env perl exit(0); # or just exit running: ./test.pl && echo "OK" || echo $? OK Having #!/usr/bin/env perl exit(123); running: ./test.pl && echo "OK" || echo $? 123 Having #!/usr/bin/env perl die; running: ./test.pl && echo "OK" || echo $? Died at ./test.pl line 2. 255 So: Exiting from perl script with 0 (or nothing) will be true in shell. Exiting from perl script with a (byte) value other than 0 will be false in shell and $? will give you the exit value. Exiting from perl script with die will be false in shell and $? will be 255 (in my case - I checked it).

Categories : Linux

Can One Bash Script Launch Multiple Other Bash Scripts?
Run them in the background, just like you would in an interactive shell. command1 & command2 & command3 & wait # Wait for all background commands to finish The commands can be just about anything, not just other bash scripts.

Categories : Linux

CGI scripts for bash commands
Try this: #!/bin/bash echo "Status: 204 No Content" ...gpio stuff... HTTP responses must start with a status line; webservers will normally add status "200 Ok" if the CGI doesn't specify one. That status must be accompanied by response body, which will form the new web page. The status you want is 204, which indicates that the request was satisfied but that there is no response and the browser should stay on the same page. Normally, this would be a response to a POST request, not a GET request, but it should work anyway. Since a 204 response does not require a response body (in fact, it doesn't permit one), it should not be necessary to output a blank line following the status line, but you might need one if the script takes a long time to run.

Categories : HTML

Bash - secure scripts
This is not a bug in your script. Your invocation is equivalent to rm test ./test.sh " ; " There is nothing you can pass in as $1 that will cause test.sh to execute arbitrary commands. Apart from the ability to read any file, including infinite ones like /dev/zero and potentially blocking ones like /dev/stdin, the only potential issue is that you can pass in option instead, like -v. This is avoided with cat -- "$1" Bash scripts are generally data safe in themselves, but like SQL injection and system() calls, injection attacks can occur when e.g. sed, awk, tar and tons of other commands are not used correctly, and quoting errors can trigger logic bugs. These things are rarely related to shell syntax like `..` or $(..) and more related to seemingly innocent strings like "w foo", so

Categories : Apache

bash scripts to compile and run C++
You are missing fi at the end, but you could also write a GNU Makefile like this: CXX=g++ CXXFLAGS=-Wall OBJS=main.o EXECUTABLE=main all: $(EXECUTABLE) $(EXECUTABLE): $(OBJS) $(CXX) $(CXXFLAGS) $(OBJS) -o $@ clean: rm -f $(EXECUTABLE) rm -f $(OBJS) main.o: main.cpp Note, this is a flexible example, and you could simplify this even further down the line. Here you can find a very good tutorial to read upon: http://mrbook.org/tutorials/make/ However, I would strongly suggest to learn cmake instead as writing Makefiles manually are painful. A CMakeLists.txt file could be something like this: add_executable(main main.cpp) then simply: mkdir -p build && cd build && cmake ../ && make VERBOSE=1 and then you would be done in a cross p

Categories : C++

Add whatis hooks into bash scripts
whatis gets all the the information from whatis database, which is generated using the command makewhatis. There are two ways you can add an entry into the database. Create and install the man page for your program or script, then run makewhatis. Edit whatis database manually.(Not suggested) makewhatis picks up the first line from the NAME section of the man page of your command. The location of whatis database on my machine is /usr/share/man/whatis, here's how it looks like.. ABORT(7) - abort the current transaction ALTER_AGGREGATE(7) - change the definition of an aggregate function ALTER_COLLATION(7) - change the definition of a collation ALTER_CONVERSION(7) - change the definition of a conversion ... ping(8) - send ICMP ECHO_R

Categories : Linux

Can Linux Bash scripts respond to install options
To establish whether the scripts support any command line options, you can: Read the readme file of the software, if there is one. This should explain any options. Read the top of the install.sh script. Usually options are at least listed there. Read the code itself, which might be a lot of work. Once you have established that the scripts do not support options, the standard way of automating this would be with an expect script. See for example automating install.sh script using an expect script. Depending on how the install script works, you may be able to send it commands on standard input. For example, if you press Tab once, then Enter, then y and lastly Enter again, you can try the following: printf %s $' y ' | ./install.sh

Categories : Linux

Checking host availability by using ping in bash scripts
Ping returns different exit codes depending on the type of error. ping 256.256.256.256 ; echo $? # 68 ping -c 1 127.0.0.1 ; echo $? # 0 ping -c 1 192.168.1.5 ; echo $? # 2 0 means host reachable 2 means unreachable

Categories : Bash

converting bash scripts to Python - how to handle heredocs?
Heredoc in Python Use multiline string (triple-quote string ''' or """). See Strings from tutorial. Run command import subprocess subprocess.Popen(['cat'], stdin=subprocess.PIPE).communicate(''' Hello multiline-string simliar to heredoc. ''')

Categories : Bash

how to get max number from a file with Linux bash shell scripts
Use sort: sort -t= -nr -k3 inputfile | head -1 For the given input, it'd return: log2c=3.0 rate=89.5039 If you want to read the values into variables, you can use the builtin read: $ IFS=$' =' read -a var <<< $(sort -t= -nr -k3 inputfile | head -1) $ echo ${var[1]} 3.0 $ echo ${var[3]} 89.5039

Categories : Bash

Is there a way to package bash shell scripts with AppleScriptObjC app on MacOSX with Xcode?
Answering my own question, after some hours of research and experimentation (with thanks to various posts on macscripter.net and autodidaktos.com): Add the script file, e.g., yourScriptFile.sh, to the project via the menu File - Add Files to (yourProject)... Include the script file in the app bundle so that it will be included with the app when distributed: In the Project Navigator or the Jump Bar select your project Select the "Build Phases" tab Expand the "Copy Bundle Resources" section (this applies to Xcode 4.6.3, maybe different with other versions) Add an item to the Bundle Resources by clicking the "+" button at the bottom of the list Select the script file to add to the bundle, e.g., yourScriptFile.sh In your AppleScriptObjC script, add the following subroutine on applica

Categories : Bash

Handling Spaces In Substring Searches In Bash Shell Scripts
You can escape the space: $mainSubString = *blue cheese* or quote the non-wildcard portions, one example of which is $mainSubString = *'blue cheese'* Often, it is better to store the pattern in a variable, both to simplify the quoting and to make the [[...]] expression more concise. Note that you must not quote the parameter expansion, as glenn jackman points out in his comment. pattern="*blue cheese*" if [[ $mainString = *cat* || $mainSubstring = $pattern ]]; then

Categories : Bash

Good way to arrange variables and command calls in bash scripts
Don't know if this is any better than what you suggested, but: env GIT_EDITOR="some interesting command with 'quoting and' spaces" "$SOME_DIR/actual_command" argument

Categories : Bash

Running a subprocess bash script from Python in the scripts current directory
Yep, Just before your loop programitically save the current working directory and change the current working directory to /some%s before the subprocess.call and then set it back to the original value when you are done. import os Orig = os.path.abspath('.') for i in range(1,100): os.chdir('/some%s' % i) subprocess.call(['./task.sh' % i, arg1]) os.chdir(Orig)

Categories : Python

How to check if running as root in a bash script
If the script really requires root access then its file permissions should reflect that. Having a root script executable by non-root users would be a red flag. I encourage you not to control access with an if check. chown root:root script.sh chmod u=rwx,go=r script.sh

Categories : Bash

alias .="cd .." causing bash to start at root
. refers to the current directory, while .. refers to the one upper in the dirs hierarchy. What must be happening is that in your bashrc you have some . after this alias definition, so it gets called and hence you are moved to the parent directory. So: you enter and you are in /home/your_home you set alias .="cd ..". some dot . is found while reading .bashrc. this dot is executed as to be an alias, so you get cd .., which moves you to /home. you probable have more than one . and it must get executed again, moving you from /home to /. Solution: Create an alias with a better name that does not have any predefined meaning. Move your alias sourcing to the bottom of .bashrc.

Categories : Bash

Jetty bash script works only with root user
Check the ${jetty.home}/logs/start.log (or similarly named log file) That will tell you why it failed. Also, you might want to look into the optional setuid support. http://www.eclipse.org/jetty/documentation/current/setuid.html

Categories : Linux

make HTML generated by content scripts of extensions inaccessible to page scripts
There aren't any special Chrome Extension techniques for this. As you'll read here, JavaScript injected via a content script is automatically sandboxed, or separated from the JavaScript on a web page, but this is not the case for HTML -- the DOM elements are shared between the page scripts and the injected content scripts.

Categories : Javascript

Contexts and methods for communication between the browser action, background scripts, and content scripts of chrome extensions?
It's been some time since I have had to deal with chrome's extensions. I remember it was quite a struggle before I got how things worked. In order for your extension to communicate with the browser it's easy you use your javascript/background file, and to communicate with the webpage you need to use chrome.tabs.executeScript but that's really tricky and can be a real pain in the butt. I suggest you take google's tour on extensions and give their api a really good overlook, everything's in there! I wish you good luck and I hope this answer has helped you! :P

Categories : Javascript

Linux skip /root/.gvfs when executing df command with non-root user
I got the solution for my own question :) In df command you can pass the file system types which you would like to exclude, in this case it is 'fuse.gvfs-fuse-daemon'. So when I execute the below the command I no more get this message "df: `/root/.gvfs': Permission denied" df -x fuse.gvfs-fuse-daemon For more details one can look into df --help option.

Categories : Linux

How to use python script to start other python scripts and check whether all "child scripts" are finished?
Try swapping the location of r.wait() and po.close() if __name__=="__main__": for dirpath, dirname , filenames in os.walk(rootdir): for filename in filenames: if filename=='Test.py': argument.append( [ dirpath, filename ] ) print argument po=multiprocessing.Pool() r=po.map_async(Openpy, argument) r.wait() po.close() It might not be your problem, but it looks like maybe you are closing the pool before the result is evaluated.

Categories : Python

Root immediate child nodes icons not visible when hiding root
JTree#setShowsRootHandles(boolean newValue) controls the state of the handles for root elements. Normally, this is false. Try changing to true

Categories : Java

Is sudo-ing tomcat's startup with a non-root user the same as running it as root?
Do be aware that the recommended solution to run tomcat on port 80 is to use mod-jk with the Apache web server, not to have tomcat listen on port 80 directly.

Categories : Unix

Switch statement using char from a string with "Error: switch quantity not an integer"
seq is a string *, not a char *, so seq[i] has type string. In C++, string is preferred over char arrays, and likewise, references are preferred over pointers, so change the declaration of your argument to string &seq so that string::operator [] can take effect and return a (reference to) char. (You can declare seq as char * too, but then that's C and not C++...)

Categories : C++

The switch statent and return values - How to use a switch to determin JPanel drawn
Declare variable as final those are used in switch case. final String pageAnimals = "pageAnimals"; final String pagePlants = "pagePlants"; Since all case labels should be compile time constants in Switch.

Categories : Java

Read and Write root folder wihout root
You can use run-as on some devices to execute commands as a particular package. Google have fixed this on Jelly Bean so it no longer works: adb shell run-as app.package.name cp /data/data/package.name/file.txt /sdcard/ exit adb pull /sdcard/file.txt ~/ Here is a good article explaining file access in Android without root permissions, including a one-liner for the above script. It details how to use the new backup command: backup -f ~/data.ab -noapk app.package.name And how to extract the contents of the resulting .ab file: dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf - You will most likely need the android.permission.BACKUP permission.

Categories : Android

Reset MAMP Pro username and password to root/root
Assuming you still know the password, you can change the password back to root using /Applications/MAMP/Library/bin/mysqladmin -u root -p password root It'll prompt you to enter a password again, after which it'll be reset to root

Categories : Mysql

Variable in switch, switch in loop, error in case 2
You've made an assumption that the compiler can't verify--that you will always generate the matrix be forming viewing it. The compiler knows that this doesn't have to be the case in a switch statement, so it prevents you from using a variable which may never have been set (or in this case, even declared). If you want to keep this code, declare the variable outside of the case and initialize it to a new matrix. Then check in case two if it is safe to display.

Categories : C#

Symfony2 user switch missing ROLE_PREVIOUS_ADMIN after switch
You should implement EquatableInterface for User class: class User implements UserInterface, EquatableInterface, Serializable { // ... public function isEqualTo(UserInterface $user) { return $this->username === $user->getUsername(); } public function serialize() { return serialize(array( $this->id, $this->username, )); } public function unserialize($serialized) { list($this->id, $this->username) = unserialize($serialized); } // ... }

Categories : PHP

SVN (svnserve) virtual root --root= not recognized
svn+ssh handles the whole transaction including writing and reading the files so it ignores the --root parameter in svnserve. Here is how to fix it over at serverfault -- Basically you just make svnserve into a script that calls svnserve with the proper variables.

Categories : Svn

Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping"
DOCTYPE for <hibernate-configuration> should be: <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

Categories : Hibernate

Set a switch on until a flag is reached and then set the switch to off
I don't know much about the system you're working on, so this is going to be some bare-bones code. Anyway, let's go through this step-by-step. Assumptions: button is a variable that is 1 if the button is currently pressed and 0 otherwise. motor is a variable that we set to 1 to turn the motor on, or 0 to turn it off. sensor is a variable that is 1 when the sensor is activated, or 0 otherwise First, we need code to toggle the motor state when the button is pressed. (Assume all code samples are inside a function called from your main loop) //values of static variables are preserved between function calls static char bActivateMotor = 0; //1 if we should activate motor, 0 otherwise static char bButtonHeld = 0; //1 if button was pressed last loop //(to differentiate between button bei

Categories : C

Switch color defined in LESS base on scala variable - switch color theme in different environment
I don't think it's possible to mix javascript and LESS in that way. I would just do something like: if (env === "DEV"){ var styleRef = document.createElement("link"); styleRef.setAttribute("rel", "stylesheet"); styleRef.setAttribute("type", "text/css"); styleRef.setAttribute("href", "dev-style.css"); document.getElementsByTagName("head")[0].appendChild(styleRef); } else if (env === "UAT"){ ... } And so on. You can then fetch the correct compiled CSS file according to your environment.

Categories : Scala

is there any method to draw a tree with a root , the root's previous nodes and successor nodes?
Couple of ideas you might find useful: You can use the tree layout to place the nodes in the canvas, create link objects pointing back and forth, then bind the link objects to a diagonal. http://www.durablejs.org/examples/flowchart/1/admin.html You can also use place the nodes using a pack layout, create the link objects pointing back and forth, and bind the links to a Bezier curve. http://www.durablejs.org/examples/statechart/1/admin.html You can find the code for the graphs above: https://github.com/jruizgit/durable/tree/master/lib/durabjevisual.js

Categories : D3 Js

How can I remove the root node and make the first child the new root node with XSLT?
Add a rule to the identity transform that adds nothing to the result tree for your document element other than the processing of its children: <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/*"> <xsl:apply-templates select="*[1]"/> </xsl:template> <xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> (edited to be agnostic to the name of the document element) (edited again to only preserve the first child element of the document element)

Categories : Xml

Including from child theme root or else include from parent theme root
To answer your question directly based on your sample, i would not check to see if the file has been placed in the child theme. If a child-theme developer has customized the file, they can simply declare the function and include their own file (wherever they place it). There is no risk of code duplication because your sample function is simple enough. Even if you simplified your code for the purposes of placing it here....you can always keep includes wrapped in a very simple function that can be declared by a child theme. This will keep PHP running efficient and not having to check for files all the time.

Categories : Wordpress

execute user inputed Windows (or bash) commands from batch (or bash) file?
Do you need a full bash prompt? Or would something like this be enough? #!/bin/bash echo -n "Enter cmd: " read COMMAND echo ${COMMAND} | bash Also, in a script, you can just execute bash and get a full prompt in the current environment.

Categories : Bash

Redirecting standard input in Bash implies that Bash executes a default action?
exec 6<&0 0</tmp/lines.txt; exec 0<&6 6<&- Turns out that bash still executes what remains in the command specified or script before it reads input for commands again that's why your file /tmp/lines.txt is not read since exec 0<&6 6<&- is run before it. Please refer back to the previous solution if you want to execute commands in /tmp/lines.txt before exec 0<&6- is executed. Also it might have not been obvious but you could use . or source to achieve same output: . /tmp/lines.txt source /tmp/lines.txt

Categories : Bash

Why does the child of an eval call from bash get orphaned once the parent bash script dies?
This is normal and expected. You sent a signal (presumably SIGTERM) to parent-script and it died, but no signal was sent to another-script. It keeps on running. This is different than what happens when the parent-script job is running interactively on a terminal and you type ^C (or ^Z). In that case, a SIGINT signal is automatically sent to the whole foreground process group. Since another-script is un the same process group as parent-script (by default), they both get the signal and they both die. If you want another-script to die automatically when its parent dies in any other context than when it's a job running in a terminal with job control, you have a few options. parent-script can trap the SIGTERM signal. In the signal handler, it kills its child, and then exits itself. This, o

Categories : Linux

Pass a full bash script line to another bash function to execute
optout is a command like any other, and so must be preceded by any local modifications to the environment. The command that optout runs will inherit that environment. CC=${BUILD_TOOL_CC} optout ./configure ${ZLIB_CONFIGURE_OPT} --prefix=${CURR_DIR}/${INSTALL_DIR} By the way, this is just one of the problems you are likely to encounter with your optout function. You cannot run arbitrary command lines in that fashion, only a simple command followed by zero or more arguments (and I would expect there are some exceptions to even that restricted set, as well).

Categories : Linux



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.