Tag Info

Hot answers tagged

17

To do that, use one extra file descriptor to switch stderr and stdout: find /var/log 3>&1 1>&2 2>&3 | tee foo.file Basically, it works, or at least I think it works, as follows: The re-directions are evaluated left-to-right. 3>&1 Makes a new file descriptor, 3 a duplicate (copy) of fd 1 (stdout). 1>&2 Make stdout (1) ...


14

Bash has a "loadable" sleep which supports fractional seconds: $ cd bash-3.2.48/examples/loadables $ make sleep && mv sleep sleep.so $ enable -f sleep.so sleep Then: $ which sleep /usr/bin/sleep $ builtin sleep sleep: usage: sleep seconds[.fraction] $ time (for f in `seq 1 10`; do sleep 0.1; done) real 0m1.000s user 0m0.004s sys ...


11

You need to use: "$@" for correct parameter expansion in all cases. This behaviour is the same in both bash and ksh. Most of the time, $* or $@ will give you what you want. However, they expand parameters with spaces in it. "$*" gives you all parameters reduced down to one. "$@" gives you what was actually passed to the wrapper script. See for yourself ...


9

The documentation for the sleep command from coreutils says: Historical implementations of sleep have required that number be an integer, and only accepted a single argument without a suffix. However, GNU sleep accepts arbitrary floating point numbers. See Floating point. Hence you can use sleep 0.1, sleep 1.0e-1 and similar arguments.


8

Kyle's Unix/Linux command does the job of switching the STDERR with the STDOUT; however the explanation is not quite right. The redirecting operators do not do any copying or duplicating, they just redirect the flow to a different direction. Rewriting Kyle's command by temporary moving the 3>&1 to the end, would make it easier to understand the concept: ...


7

rm -- ----------9976723563nneh4_-----192.9.200.4 You need -- in order to tell rm (and more or less all other GNU software) that all following parameters are file names even when beginning with "-". Otherwise (and in your case) the file name is confused with options. Another possibility is rm ./----------9976723563nneh4_-----192.9.200.4 Edit 1 Calling ...


6

I believe something as simple as 'sort -u ' should work for you #sort -u /tmp/test 172.17.200.1 3.3.3.3 172.17.200.2 3.3.3.4 172.17.200.3 3.3.3.5 172.17.200.4 3.3.3.7 172.17.200.5 3.3.3.8 255.255.255.0 255.255.255.111 Check the 'sort' manpage for more info: -u, --unique with -c, check for strict ordering; without -c, output only the first of an equal ...


5

somthing like: while read LINEVAR ; do echo ${LINEVAR} ; done < myfile.txt which will read one line of input from myfile.txt at a time?


5

If you want to log what your users are doing then take a look at snoopy. It's also available as a package to install for CentOS.


5

The -f option allows you to overwrite the target file, i.e. the file with the name you're creating the link with, with a new link. It doesn't check for other links in the same directory. Example: $ touch file1 $ touch file2 $ ln -s file1 link1 $ ls -l total 8 -rw-r--r-- 1 jenny staff 0 Mar 16 21:13 file1 -rw-r--r-- 1 jenny staff 0 Mar 16 21:13 ...


4

It strips the base off of the path to the file. In variable expansion, ## means "take the thing to my right, treat it as a pattern, and delete the longest match of it in the variable to my left." In this case the pattern is /*/, so the longest match of that in a variable which included a path and filename would be the path. Deleting it would leave only ...


4

Here's a solution for sending all commands executed to a syslog server. http://blog.rootshell.be/2009/02/28/bash-history-to-syslog/ Extract from the blog post Here are two methods to send a copy of all commands executed by the users to a Syslog server. The first one will use the Bash “trap” feature. The second one is a patch to apply in the Bash source ...


4

You need two equal signs: [[ $a == signature.pl ]] && echo equal


4

The following is a suitable regex, split onto 4 different lines for the sake of my own sanity. (1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\. (1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\. (1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\. (1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]) Output: egrep -o `cat regex` infile #all regex lines above joined, no spaces 1.1.1.1 1.1.1.133 31.1.1.1 ...


4

maybe with cut instead of sed? echo "10.10.10.5" | cut -d. -f-3 if it has to be sed echo "10.10.10.5fsdfdsf" | sed -e 's/\.[^\.]*$//'


3

Sun published a Linux to Solaris Admin Guide (PDF) that describes the key differences, commands, file structure, monitoring, etc. between the two OSes; it's from 2007, but it's likely still very relevant. There's also a brief Quick Reference Guide at the end.


3

In summary, no. oslevel -s 5300-08-03-0831 /usr/bin/ksh - Version M-11/16/88 /usr/bin/ksh93 - Version M-12/28/93 The version may differ slightly between different TL/SP levels in AIX. AIX by default uses ksh, and very little uses ksh93. Obviously, you can configure your script to use /usr/bin/ksh93. /usr/bin/ksh93 is provided by the same fileset ...


3

I also had this problem, when for a little i switched from linux only env to mixed sun solaris and linux env. I have to say that since then, i love solaris. Once you get use with different tools (give a look at this link http://bhami.com/rosetta.html ) then you'll find how powerful is solaris. Search on google for "Less known Solaris Features" and you'll ...


3

I have found opencsw very useful you can install a selection of GNU apps from there and they have a package manager simular to apt-get called pkg-get www.opencsw.org Useful packages gsed gawk gdate gives you the latest gnu versions of these apps so you dont have to have different awk scripts depending on the OS


3

Try this: stty -a and see if lnext is ^V. If not, try: stty lnext ^V where you will type "^" (caret) and "V" as separate characters. Now try to see if you can type an escape using ^V^[ (does ^VEsc work on your keyboard?). Also, check to see if you're in emacs mode Depending on how you're using it, there are a few other ways to use escape in a Korn ...


3

Edit the /etc/motd file, no script needed.


3

It's slightly cleaner with perl #!/usr/bin/perl use Regexp::Common qw/net/; while (<>) { print $1, "\n" if /($RE{net}{IPv4})/; } but it still gets false positives 1.1.1.1 1.1.1.133 31.1.1.1 5.5.5.5 1.1.1.134 192.9.30.174 5.5.5.5 5.5.5.5 5.5.5.5 22.22.22.22 172.78.0.1 Perl one liner perl -e 'use Regexp::Common qw/net/;while (<>) ...


3

Just remove the "-eq 0 " [[ ` echo $FILE | grep -v '[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}' ` ]] && echo Not Backup file


3

Sleep accepts decimal numbers so you can break it down this like: 1/2 of a second sleep 0.5 1/100 of a second sleep 0.01 So for a millisecond you would want sleep 0.001


3

On Solaris, try using /usr/ucb/ps -auxwww | grep my_script.sh instead. This will show the full command line and arguments of the process. For Linux, simply use ps aux. Also try experimenting with forcing certain fields only to be displayed by ps, e.g. ps -ao comm,args will display the command and its arguments. A bit of time spent in man ps should get you ...


3

If you are using the bash shell you can Use parameter expansion: ifconfig -a | /usr/xpg4/bin/grep "${IP_ADDRESS//./\\.}" If your shell doesn't support this type of parameter expansion, you could use shell expansion instead, e.g. with sed: ifconfig -a | /usr/xpg4/bin/grep `echo $IP_ADDRESS | sed 's/\./\\./g'` or perl: ifconfig -a | /usr/xpg4/bin/grep ...


3

or use another separator like "|", i tried it on mac. $ date="[`date +%d"/"%b"/"%G"-"%T`]" $ echo $date [21/Feb/2013-21:17:22] $ cat /tmp/a param1=3478374 param2=34128374 param3=34783743 $ sed "s|^|$date |g" /tmp/a [21/Feb/2013-21:14:15] param1=3478374 [21/Feb/2013-21:14:15] param2=34128374 [21/Feb/2013-21:14:15] param3=34783743


3

In your .profile add the line export ENV=$HOME/.kshrc


3

Why sed? How about manipulating with bash parameter expansion? var="192.168.200.1" echo ${var%.*} 192.168.200


2

according to the man page for ksh (pdksh), you can just do: Command 2>&1 >/dev/null | cat -n i.e. dup stderr to stdout, redirect stdout to /dev/null, then pipe into 'cat -n' works on pdksh on my system: $ errorecho(){ echo "$@" >&2;} $ errorecho foo foo $ errorecho foo >/dev/null # should still display even with stdout redirected foo $ ...



Only top voted, non community-wiki answers of a minimum length are eligible