Tag Info

New answers tagged

0

lock the whole account! echo "passwd --unlock $USER" | sudo at tomorrow echo "passwd --lock $USER" | sudo logout


1

Measure the computational power of the computer Calculate the asymmetric encryption key length that's needed such that the computer would be able to brute force the key in more or less 24 hours Find a way to find a number that satisfies the property of a public key without knowing the private key (or more weakly, generate a key pair then throw away the ...


0

Changing the script to #!/bin/sh QUICKPARLOCATION="c:\\foldername\\PDFXCview.exe" PARAM=`winepath -w "$*"` wine "$QUICKPARLOCATION" "$PARAM" exit 0 and adding the program in the "Open with other application-->Use a custom program:" menu, solves the problem.


-2

The following script is easy to understand and easy to use. cat filename | tr ' ' '\n' | tee filename


1

I think, if possible, it would have to involve encryption - nothing is denied to root (not memory access, not any disk access at any level, not access to mess with the clock to make it look like time has passed when it hasn't). If the data is on the disk, in a file, already, then an administrator can access that. Solution 1: Easiest/most reliable solution: ...


0

To improve upon SLM's answer you can also make this work for files that start with a number by creating 0-9 directories: mkdir -p output/{A..Z}; mkdir -p output/{0..9}; for i in tstdir/*; do export FILE=$(basename "$i"); LTR=$(echo "${FILE:0:1}" | tr [a-z] [A-Z]); mv "$i" "output/$LTR/$FILE" ; done


1

Check whether the history number was incremented. A cancelled prompt or a prompt where the user just pressed Enter won't increment the history number. The history number is available in the variable HISTCMD, but this is not available in PROMPT_COMMAND (because what you want there is in fact the history number of the previous command; the command that ...


1

(I know it's late, but hoping someone could use it.) I've had great results with this combination: ps -p $$ | awk '$1 != "PID" {print $(NF)}' Edit 1: On Tru64 (OSF/1), the output has parentheses around the shell. Tack on tr -d '()' to remove them. ps -p $$ | awk '$1 != "PID" {print $(NF)}' | tr -d '()' Appears to works on all shells, on ...


0

Answering my own question: CUT_LOG=A0000096.LOG #Actually, Logic goes here to determine name of file. LISTLOG=`ls -1 /Source_Dir/A*.LOG | sed "/$CUT_LOG/,$ d"` # Create a list that has only relevant entries # sed deletes all lines starting from pattern matching line till ...


1

Newer derivatives of the OpenBSD netcat, including FreeBSD[1] and Debian[2], support a -d flag which prevents reading from stdin and fixes the problem you described. The problem is that netcat is polling stdin as well as its "network" fd, and stdin is reopened from /dev/null in the second case above, where the shell function is run in the background before ...


0

This is explained in the Bash manual section on Redirections. Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form {varname}. In this case, for each redirection operator except >&- and <&-, the shell will allocate a file descriptor greater than 10 and assign it to {varname}. If ...


-2

It seems that I found the right answer to my own question: Bash is buggy as it does not manage it's own locale. So setting LC_* in a bash process is without effect in that shell process. If you set the LC_COLLATE=C and then start another bash, the globbing works as expected in the new bash process.


22

Note that when using range expressions like [a-z], letters of the other case may be included, depending on the setting of LC_COLLATE. LC_COLLATE is a variable which determines the collation order used when sorting the results of pathname expansion, and determines the behavior of range expressions, equivalence classes, and collating sequences within ...


15

[A-Z] in bash matches all characters that sort after A and sort before Z. In your locale, c probably sorts in-between B and C. $ printf '%s\n' A a á b B c C Ç z Z Ẑ | sort a A á b B c C Ç z Z Ẑ So c or z would be matched by [A-Z], but not Ẑ or a. $ printf '%s\n' A a á b B c C Ç z Z Ẑ | pipe> bash -c 'while IFS= read -r x; do case $x in [A-Z]) echo ...


5

It's intended and documented in bash documentation, pattern matching section. The range expression [X-Y] will be included any characters between X and Y using the current locale’s collating sequence and character set: LC_ALL=en_US.utf8 bash -c 'case b in [A-Z]) echo yes; esac' yes You can see, b sorted between A and Z in en_US.utf8 locale. You have some ...


1

Locale can change what characters are matched by [A-Z]. Use (LC_ALL=C; rm [A-Z]*) to eliminate the influence. (I used a subshell to localize the change).


3

That part: echo "{@@##}RETURN_REAL_STATUS_SCRIPT=${?}" Just prints: {@@##}RETURN_REAL_STATUS_SCRIPT=x where the last x is replaces by the value of variable $?. From the bash manpage: ? Expands to the exit status of the most recently executed foreground pipeline. That means that $? contains the exit code of the previously executed command: ...


0

One small addition to the above script. The -P option to pwd follows symlinks DIR="$(cd "$(dirname "$0")" && pwd -P)"


2

Use this: security find-certificate -c "certificatename" -a -Z | \ sudo awk '/SHA-1/{system("security delete-certificate -Z "$NF)}' awk is called with sudo. awk then searches for the string SHA-1 and calls the security delete-certificate command with the hash as argument. You have to provide the sudo password only once.


2

Use "seq" - print a sequence of numbers seq FIRST INCREMENT LAST for i in $(seq 4.00 0.02 5.42) do echo $i done


1

There is a workaround, but it has some requirements: You need to set $HISTCONTROL to save ALL commands, also duplicates and spaces. So set: HISTCONTROL= Now define a function to call as $PROMPT_COMMAND: isnewline () { # read the last history number prompt_command__isnewline__last="$prompt_command__isnewline__curr" # get the current history number ...


0

I don’t know of a way to do that, per se.  But you can get the same effect by using trap some_command_or_function debug This will causes the some_command_or_function to be called any time you run a command.  The tricky thing is, it will not be called if you just hit Enter — unless you have a PROMPT_COMMAND defined, in which case hitting Enter invokes the ...


2

Basically, you are talking about a chroot environment, when a user or group meets some usage restrictions by having only specific binaries and configs in their directory root level. It is possible to configure sshd to do that. /etc/ssh/sshd_config options: Match user john ChrootDirectory /var/john/ Put /bin, /etc, /sbin, /usr and other required ...


1

Building on orion's answer, the less(1) man page describes /pattern Search forward in the file for the N-th line containing the pattern.  N † defaults to 1.  The pattern is a regular expression, as recognized by the regular expression library supplied by your system.  The search starts at the second line displayed (but see the -a and ...


2

#!/usr/bin/env bash countdown() { i=$1 while [ $i -gt 0 ]; do printf "Starting in %d...\n" $i sleep 1 i=$(( i - 1 )) done } countdown 3 Now, if you want to be fancy, tput might be worth looking into: tcountdown() { i=$1 clear while [ $i -gt 0 ]; do tput cup $(( i - 1 )) 40 printf $i sleep 1 i=$(( i - 1 )) done ...


4

Replace "discription" by "description:" (typo and missing colon). RHEL 5 needs "chkconfig:" and "description:", RHEL6 only "chkconfig:".


1

You'll need to extract the variables from the arguments first to get the values substituted into the template. You do this in a really odd way: args=("$@") operation=("${args[0]}") channel=("${args[1]}") accountcode=("${args[2]}") channelname=("${args[3]}") music=("${args[6]}") prevchannel=("${args[4]}") prevchannelname=("${args[5]}") operation is an ...


2

Only one argument can be passed to an option, but you may specify a,b,c and later temporarily set IFS to ',' and use read to split the argument a,b,c into three words. For example: $ OPTARG="1,do,loop" $ IFS=, read n patt file <<<"$OPTARG" $ echo $n; echo $patt; echo $file 1 do loop


0

Your answer is interesting but quite long. If you want arbitrarily large numbers, then you could join multiple random numbers in a helper: # $1 - number of 'digits' of size base function random_helper() { base=32768 random=0 for((i=0; i<$1; ++i)); do let "random+=$RANDOM*($base**$i)" done echo $random } If the problem is bias, then just ...


0

As others have suggested, you can use bc: i="4.00" while [[ "$(bc <<< "$i < 5.42")" == "1" ]]; do # do something with i i="$(bc <<< "$i + 0.02")" done


13

Avoid loops in shells. If you want to do arithmetic, use awk or bc: awk ' BEGIN{ for (i = 4.00; i < 5.42; i+ = 0.02) print i }' Or bc << EOF for (i = 4.00; i < 5.42; i += 0.02) i EOF Note that awk (contrary to bc) works with your processors double floating point number representation (likely IEEE 754 type). As a result, ...


17

Reading the bash man page gives the following information: for (( expr1 ; expr2 ; expr3 )) ; do list ; done First, the arithmetic expression expr1 is evaluated according to the rules described below under ARITHMETIC EVALUATION. [...] and then we get this section ARITHMETIC EVALUATION The shell allows arithmetic expressions to be ...


0

The modulefile man page is probably of more use to you than the module man page. A search for "environment module examples" yields this page, which seems to have some good examples. I think it addresses most of your questions: If I install a program from source, how do I make it available to load it as a module? Install the package somewhere and then ...


0

I ended up hacking this thing together: import subprocess import time import sys log = open(sys.argv[3], 'w') input = open(sys.argv[2], 'r') p = subprocess.Popen([sys.argv[1]], stdin=subprocess.PIPE, stdout=subprocess.PIPE) def readAllSoFar(proc, retVal=''): while (subprocess.select.select([proc.stdout],[],[],0)[0]!=[]): ...


0

The answer by Glenn is of course mighty fine, but in this type of cases I would use awk to generate the command lines, and then pipe the results to a shell. As awk is part of POSIX, it arguably would be a valid solution. awk -F'[, ]+' '{print "rectang -cs", $1, $2, $3, $4}' table.csv | sh or, assigning the first field to the first field to trigger a ...


6

It's not that much that there's not output as it's coming in chunks. Like many programs, when its output is no longer a terminal, cut buffers its output. That is, it only writes data when it has accumulated a buffer-full of it. Typically, something like 4 or 8 kiB though YMMV. You can easily verify it by comparing: (echo foo; sleep 1; echo bar) | cut -c2- ...


2

The read command can grab multiple words, separated by characters in $IFS (default: space, tab, newline) while read -r d1 d2 d3 d4; do rectang -cs "$d1" "$d2" "$d3" "$d4" done < file.csv Given your modified data (fields separated with comma and spaces), I'd do this: while IFS=",$IFS" read -r d1 d2 d3 d4; do # ... to include the comma as a ...


0

If the file is like that: cat table.txt | while read i do rectang -cs $i done This will call: rectang -cs 5 6 9 5 rectang -cs 2 8 1 1 etc.


1

This should do: #!/bin/bash # this is the crucial setting: replace a glob pattern that matches zero files # with nothing (the default is to *not* replace the pattern at all) shopt -s nullglob destination=/some/directory unique_filename() { local root=${1%_*}_ local files=( "$destination/$root"* ) echo "$destination/${root}${#files}" } cd ...


0

Thanks for all the answers. I used a combination answers to achieve my desired result. #!/bin/bash isTable=0 beginTable="^\|\|" lineNum=1 tableCount=0 while IFS= read -r line #Print changes to temp file do if [[ $line =~ $beginTable ]] then if [ "$isTable" -eq "0" ] then isTable=1 ((tableCount++)) ...


0

tail -f /var/log/squid/access.log | ( c=0; pl() { echo $c; c=0; }; trap pl SIGHUP; while read a; do (( c=c+1 )); done ) & ( trap 'kill $! ; exit' SIGINT; trap '' SIGHUP; while true; do kill -HUP $! ; sleep 1; done)


8

Your Ctrl-r is being intercepted by the kernel-based terminal cookied line processing engine. While sleep is running, the terminal is in cooked mode, which means that the kernel-based tty line editor is working. The tty line editor supports rudimentary command line editing. The erase key (usually set to Ctrl-h (backspace) or Del) and the kill key (usually ...


1

If you like to time commands for performance reasons, I recommend not to use /usr/bin/time but either ptime(1) if this available on your platform - ptime gives a nanosecond resolution - or to use a recent Bourne Shell, as the Bourne Shell allows to automatically time all foreground commands (including shell builtins) with a microsecond resolution on all ...


5

The structure of a pipeline doesn't allow time in the middle, only at the start of the pipeline. Also, time is a "shell keyword", as shown by type time. But nothing forbids the use of compound commands (and time each): time comm1 | ( time comm2 ) So, you could workaround using a sub-shell, like this: echo "12" | ( time python3 -c "a=input("");print(a)" ...


1

In bash you can do indirection on a variable with the syntax ${!var}. E.g. a=x; b=a; echo "${!b}" # gives you x Other bash-isms you might like can replace eg: xml_attrib=`echo $line | cut -d "=" -f1` xml_value=`echo $line | tr -d '"' | cut -d "=" -f2` by xml_attrib=${line%%=*} line=${line#*=} xml_value=${line//\"/} See bash(1), Parameter ...


3

There is two types of time commands. One is shell built-in, belongs to bash. That's the one you see in your first example. Second one , is /usr/bin/time, that's the second one you saw. As for why it's different output, it's because you cannot pipe output to shell builtins. More on that here


1

As a start ... xrandr | awk -F ' *|x' '/^ +[0-9]/{printf("%5sx%-6s %.2f\n", $2, $3, $2 / $3)}'


3

No need for echo, no need for other other useless commands, single awk should do the job: $ xrandr | awk -F'[x ]' '/^ /{print $4"x"$5" \t"$4/$5}' 1024x600 1.70667 800x600 1.33333 640x480 1.33333


0

I noticed that I had to devide instead of multiply, so the error causing asterisk is gone. This works whithout awk and bc: xrandr|egrep "x[[:digit:]]+ "|cut -f 4 -d" "|sed 's/x/00 \/ /g'|while read i; do echo "$i = "$(expr $i); done my result (selected in the console with CTRL hold): 3200 / 1800 = 1.77 2048 / 1536 = 1.33 1920 / 1440 = 1.33 1856 / 1392 = ...


1

Something like that? xrandr | awk '/^ +[0-9]/ {gsub(/x/,"/"); print $1}' | bc -l



Top 50 recent answers are included