jim mcnamara 19 Junior Poster

Since the homework deadline has gone by and somebody may search.

One simple way with sed

# using sed for  wc -l 
sed -n  '$='  filename
jim mcnamara 19 Junior Poster

Another option: grep.

You have to show effort before we do your homework for you.

There is also a sed one hunk of code that does it as well.

You can also use a while ... do .. done loop.

jim mcnamara 19 Junior Poster

Since this is in Shell scripting:

pid=$$

$$ returns the pid of the current process (the one the shell is running in)

jim mcnamara 19 Junior Poster

HPUX supports alloca() -
it has advantages and disadvantages

good - it automatically frees all objects created by alloca calls when
         the function making those calls exits

good - it is about 100X faster than malloc

bad - it allocates from stack, not heap.  stack space size limits
       are nowhere near a generous
bad - it is REALLY easy to reference a pointer to garbage 
       or trash the  stack of another function

Example mediocre code:

#include <stdlib.h>
#include <time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>     
#include <alloca.h>
#define MAX 100000
void foo(void)
{
	int i=0;
	char *p[MAX]={NULL};
	for ( i = 0 ; i < MAX ; i++ )
		p[i] = malloc( rand()%456 );
	for ( i = MAX ; i>0 ; i-- )free( p[i] );

}
int foo1(void)
{
	int i=0;
	char *p[MAX]={NULL};
	for ( i = 0 ; i < MAX ; i++ )
		p[i] = alloca( rand()%456 );	
}

void badfoo(void)
{
	int i=0;
	char *p[MAX]={NULL};
	for ( i = 0 ; i < MAX ; i++ )
		p[i] = malloc( rand()%456 );
}

void process(struct rusage *p, char *when)
{
	printf("%s\n", when);
	printf(" /* user time used */                   %8d  %8d\n",  p->ru_utime.tv_sec,p->ru_utime.tv_usec   );
	printf(" /* system time used */                 %8d  %8d\n",  p->ru_stime.tv_sec,p->ru_stime.tv_usec   );
	printf(" /* integral shared memory size */      %8d\n",  p->ru_ixrss           );
	printf(" /* integral unshared data  */          %8d\n",  p->ru_idrss           );
	printf(" /* integral unshared stack  */         %8d\n",  p->ru_isrss           );

}


int main()
{
	  int ret=0;
	  int i=0;
	  int who= RUSAGE_SELF; …
jim mcnamara 19 Junior Poster

This is actually an Oracle question:
dba_profiles sets the rules for the system, not how many login failures there are for a given user.

Offhand I do not know what SYS table Oracle currently uses to store this information. Plus, this approach is an idea that is doomed to failure unless the dba does a

GRANT SELECT ON <whatever the underlying table is>  to PUBLIC;

which could very well be against most security policies.
Most tables relating to security are carefully protected.

jim mcnamara 19 Junior Poster

I'd use arrays:

#!/bin/ksh
optfile=filename
set -A opts  \
$(awk 'BEGIN {FS="="} { if($0~ / page_size/) { prinf("%s  ", $2}}' $optfile; echo"")
for i in 0 1 2
do
    echo ${opts[i]}
done

If you're using bash just "declare" opts as an array.

I changed it so awk puts it all on the same line.

jim mcnamara 19 Junior Poster

I'd use arrays:

#!/bin/ksh
optfile=filename
set -A opts $(awk 'BEGIN {FS="="} { if($0~ / page_size/) { print $2}}' $optfile)
for i in 0 1 2
do
    echo ${opts[i]}
done

If you're using bash just "declare" opts as an array.

WolfPack commented: Thanks. +3
jim mcnamara 19 Junior Poster
#!/bin/bash
# we want to copy from path1 to path2 
# step 1 make all the subdirectories
find /path1 -type d | \
while read dir 
do
    mkdir /path2"${dir#/path1}"
done
# step 2 cp the files
find /path1 -type f | \
while read $file
do
     cp "$file" /path2"${file#/path1}"
done
jim mcnamara 19 Junior Poster

This checks $2 to see if ".kext" is anywhere in the $2 parameter

echo "$2" | grep -q '.kext'
if [[ $? -eq 0 ]] ; then   
  echo '.kext found'
else
  echo '.kext not found'
fi
jim mcnamara 19 Junior Poster

In that case you have to use cp. mv does not mv over mount points.

jim mcnamara 19 Junior Poster

awk works for this pretty well -

awk '{
        print $0
        if($0=="Line2") {print "INSERTLINE2"}
        if($0=="Line3") {print "INSERTLINE3"}
       }' file > newfile
jim mcnamara 19 Junior Poster
cat /proc/meminfo

shows the current state of memory. The format varies somewhat with Linux distributions. My version of Linux has what you want in the 4 th column on the second line. So, you will need to get the awk statement working for you. Then put it in the C code.
You could also just read /proc/meminfo (read only) as a regular file and find the value using C only.
snippet:

#include <stdio.h>
void foo(void)
{
   char *cmd="awk '{ if(NR==2){print $4}}' /proc/meminfo";
   FILE *cmdfile=popen(cmd,"r");
   char result[256]={0x0};
   while(fgets(result,sizeof(result),cmdfile)!=NULL) 
   {
       printf("%s\n",result);
   }
   pclose(cmdfile);
}
jim mcnamara 19 Junior Poster

Use

mailx -r '<from name>' -s '<subject here>'  john@somewhere.com < message_text_file
jim mcnamara 19 Junior Poster
cd /to/my/directory
find .  -name '*.jpg' | \
while read file
do
    mv $file "new"$file
done

PS: mv works only within a filesystem. Even though you may be
in directories that are close in terms of directory trees does not mean there are no intervening mountpoints. -

jim mcnamara 19 Junior Poster

Are you talking about using NFA regexp in a DFA environment?
Start with a DFA tool is the simple answer. There really is no code to convert from one to another, because it doesn't make much sense to do so. C and C++ have regexp libraries available for them. Pick one. Windows provides the .NET version.

You do realize that which tool you use dictates which type of regex processing occurs? To get a list of which tools have what regex flavor (including POSIX) try:

J Friedl 'Mastering Regular Expressions' 2nd ed 2004

Then if you want, download source for one of them.

jim mcnamara 19 Junior Poster

find syntax is wrong there has to be a path
find PATH -name

In your case it looks like you should use a . (a dot ) which means the
current working directory.

jim mcnamara 19 Junior Poster
#!/bin/ksh
find /path/to/files -name 'tmp_*' | \
while read filename
do
      tmpfile=${filename#tmp_}
      mv "$filename"   "emkt""$tmpfile"
done
jim mcnamara 19 Junior Poster

try an alias:

alias home="cd /home/budroeducom"
alias cd1="cd /some/longpath/to/somewhere"

typing

home

will execute

cd /home/budroeducom

To see what alias commands are already there:

alias

will list them for you.

jim mcnamara 19 Junior Poster

First off, hints can be overridden by the Oracle optimizer. Just so you know.

If you want to track performance do this:
1. Before you run your SQL
ALTER SESSION SET SQL_TRACE TRUE;
run your sql
ALTER SESSION SET SQL_TRACE FALSE;
2. Now find where the trace file is:
select value from V$PARAMETER where NAME='user_dump_dest';
3. go to that directory, find the most recent file. Trace files end in .trc
4. There is a program tkprof, it's part of Oracle. Locate it.
Then run tkprof <tracefilename.trc> <outputfile>

The information you want is in the output file.

However, because Oracle caches everything, times will be misleading if you run the identical script again. Find a way to get 500 rows, then
when you run again, find 500 different rows - to avoid the effect of caching.

jim mcnamara 19 Junior Poster

This is more complex than you might think. Here is an in-depth article on sending email:
http://asktom.oracle.com/pls/ask/f?p=4950:8:6225936216616544881::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:255615160805

jim mcnamara 19 Junior Poster

/etc/profile for "world" wide variables. The basic PATH and sometimes TMOUT is usually set here.

.bashrc or .profile for a given user or yourself.
Edit the file and add something like:

export MYVAR="SOME VALUE"

Save the file, then source it

source .bashrc 
# or
source .profile

That what you mean?

jim mcnamara 19 Junior Poster

You are absolutely correct - you cannot use strtok() for more than one "parse" at a time.

jim mcnamara 19 Junior Poster

You are not calling strtok correctly.

try something like this:

void foo(char *string1, char *string2)
{
    char *first=strtok(string1,"|");
    char *second=string2(string2,"|");
    while(first!=NULL)
    {
        printf("%s\n",first);
        first=strtok(NULL,"|");
    }
    while(second!=NULL)
    {
        printf("%s\n",second);
        second=strtok(NULL,"|");    
    }
}
jim mcnamara 19 Junior Poster

Your logic doesn't make any sense to me...

You want to get to the "got it" statement - this does it.

#!bin/ksh
a=5
while [[ $a -gt 5 ]]
do
	echo "a=5 and not went to else cdn."

	if [[ $a==5 ]]
	then
		echo "a=6" 
	fi
	echo "a=5 and not worked" 
done
echo "got it"
jim mcnamara 19 Junior Poster

It's giving you the ip. putty connects over the network.

Are you not connected to the remote box?

Plus, who is POSIX.2. If the box on the other end is not POSIX-compliant , or is a version of , say, Solaris or HPUX, from before 1994, then it won't work the way you expect.

jim mcnamara 19 Junior Poster

[ -d $1 ] on line 59
test is postive when $1 is a directory.

Your logic is reversed - you display "is in the current directory"
when this test is true, when the file is a directory.

jim mcnamara 19 Junior Poster

Not to inject extra complexity, but if you need to get those exterior circles to fit together into a nice ring, with each smaller circle touching it's neighbor and the circumference of the big one, then it's math time.
See the Soddy circle page on Mathworld:

http://mathworld.wolfram.com/SoddyCircles.html
Look for Bllew's work (3). Depending on the number of "excircles", it may simply to something easy like the Descartes Circle Theorem.

jim mcnamara 19 Junior Poster

Here is a tutorial, follow the link for deinterlacing

http://www.100fps.com/

Most video processing software can do it.

jim mcnamara 19 Junior Poster

Here is why it happened:
C programs live in memory as segments. The segments have
names like TEXT and BSS. Anyway, const values get placed in read-only memory, one of the segments. The read/write DATA segment is always created, and it looks like your compiler bent over backwards to allow you to write someplace, probably there.

Bottom line: you've got undefined behavior. That means there is no real explanation for the behavior you see and no expectation or guarantee that it will ever work.

jim mcnamara 19 Junior Poster

You need to use coprocesses to have a read timeout. At least that is the only way I know to do it in ksh. bash read has a timeout
two separate scripts:
main.sh & asynch_signal.sh

asynch_signal.sh

#!/bin/ksh
# file: asynch_signal.shl  send a signal to parent process after $1 seconds
sleep $1
kill -USR2 $PPID
exit

main.sh

#!/bin/ksh

input="@@@"

# function to create asyncronous read termination
readit()
{
  trap "return" USR2
  asynch_signal.shl 10 |&
  read input
# turn off trap because we got input
  trap "" USR2

}

while [[ "$input" = "@@@" ]]
do
    echo "stuff"
    readit
done
echo "broke out of loop"
exit

Please note this is not like a keypress event in windows, the user has to hit return.

jim mcnamara 19 Junior Poster

Choices
1. install GNU date (the linux version) so you can use the --date option.
Also check the man page for your current version of date - it may be a GNU variant.

2. use C's strptime() function and strftime() function in a small C program

3. install the DATE module for perl, use str2time and format the date

jim mcnamara 19 Junior Poster
jim mcnamara 19 Junior Poster

If the js is visible like that, then you can wget the file, and I guess curl works too.

jim mcnamara 19 Junior Poster

One way is to write a short script that compares files with like names:

#/bin/ksh

export PATH1=/path/to/folder1
export PATH2=/path/to/folder2

find $PATH1 -name '*' | \
while read file
do 
	base="`basename "$file"`"
	if [[ `cmp "$file" "$PATH2/""$base" 2>&1 > /dev/null; echo $?` -eq 1 ]] ; then
		echo "$file" " " "$PATH2/""$base"
		diff "$file"  "$PATH2/""$base"
	fi
done > diff.log

All the " " are there in case filenames have spaces.

jim mcnamara 19 Junior Poster

You will have to try to download the separate file, which ought to be protected, but looks like it is not.

It's the same ideas as downloading a script like this:

grep 'stuff' myfile

The download does not get the grep executable. Same idea.

jim mcnamara 19 Junior Poster

First off:
-y produces side by side output. diff tries to fit two lines into 80 columns, that's why the lines are truncated.

-r displays a filename. otherwise you would never know what the diff output was based on.

what are you trying to do? && what output would you like to have?

jim mcnamara 19 Junior Poster

There isn't "a" version of UNIX. pty is suggesting the BSD version of UNIX manifested as Linux. Good choice.

There are other families of UNIX out there. POSIX was created to try to make "one" UNIX specifications so it was easier to work and port across platforms.

jim mcnamara 19 Junior Poster

It sounds like you have to set bits to toggle pixels on the display?

Or does the display have an embedded driver to respond to ANSI tty commands?

jim mcnamara 19 Junior Poster

shell programming and C/C++ are not the same thing. maybe a moderator will move your post for you.

Anyway, in shell there is no way without writing code (the ncurses library provides calls to do this) without resorting to C/C++ code. Plus you have to be in graphics mode....

see for someone with the same probleem.:
http://www.unix.com/showthread.php?t=26162&highlight=cursor+position

jim mcnamara 19 Junior Poster
tr -s '[:lower:]'  '[:upper:]'  < filename > newfilename

You have to use POSIX character classes, not "regex" classes.
this: < filename > filename : causes filename to be truncated to zero length BEFORE tr runs.

jim mcnamara 19 Junior Poster

Absolutely. C++ is used extensively in developing some components of games.

jim mcnamara 19 Junior Poster

Have you tried it - it looks like it will work, depnding on the shell you use.

jim mcnamara 19 Junior Poster

I think he means what will print the username

/* windows: */
#include <windows.h>
void MyNameIs(void)
{
    char username[24]={0x0};
    GetUserName(username,sizeof(username));
     printf("%s\n", username);

}

/* unix */
#include <unistd.h>
void MyNameIs(void)
{
    char *username=getlogin();
    printf("%s\n", username);
    
}
jim mcnamara 19 Junior Poster

Favorites is a shell folder, meaning what it's name and location are depend on explorer.exe It's not a regular file, so you have to call the SH api. Here is an example that gets the path to favorites:

#include <windows.h>

char *favorites_path(char *destination_path)
{
    ITEMIDLIST IDL;
    int rc;
    
    *destination_path=0x0;
    rc=SHGetSpecialFolderLocation(100, CSIDL_FAVORITES, IDL);
    if(rc==NOERROR)
    {
         rc = SHGetPathFromIDList(IDL.mkid.cb, destination_path);
         /*  you can check the rc here and something in case of failure */
     }
    return destination_path;
}

PS: it's six years since I did this, so take that into consideration....

jim mcnamara 19 Junior Poster

Here is a start - you need to read up on shell scripting

#!/bin/ksh

# function gen_data
# record performance data, place in a file with each node's
#    information all on one line
gen_data()
{
    for i in 54 72 114 122 123 139 73
    do 
        ssh 10.42.1.$i "hostname && uptime"  
    done | \
    awk ' BEGIN {cnt=0}
        { printf("%s, ", $0)
          cnt++
          if(cnt % 3 == 0) {printf("\n") }
        }' > ./perf_data
}

#function check_data
# check for load averages (fields 6,7,8) which are greater than 7

check_data()
{
	awk -F"," '{ if($6 > 7.0 || $7 > 7.0 || $8 > 7.0) 
	                 {print $0 } 
	           }' ./perf_data > ./email.dat
	           
# do we have any warnings to email ?	           

	if [ -s email.dat ]; then
	   cat ./email.dat | \
	       usr/bin/mailx -s 'Performance warning' you@someplace.com
	fi
}

# main control loop
# run the two functions every ten minutes  60 seconds * 10 = 600

sleepy_time=600

# loop forever .....
while true
do
	gen_data
	check_data
	cat ./perf_data >> ./perf_data.log
	sleep $sleepy_time
done
evlmcgyver commented: Excellent! Clean, neat, and tidy!! +0
jim mcnamara 19 Junior Poster

For starters we need to know what flavor(s) of unix are involved.

And, to keep to you busy, you'll need to be sure to have set up authentication keys between the main host and the remotes so that ssh will work in a script..... they may well be set up already.

jim mcnamara 19 Junior Poster

Some exit codes are expected under certain circumstances in decent shell code and should be used for those conditions:

http://www.tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF

Another point of view is to standardize your exit codes using the values taken from the C header file sysexits.h

http://cvs.opensolaris.org/source/xref/on/usr/src/head/sysexits.h

jim mcnamara 19 Junior Poster

or try

. myscript.sh
#or
source .myscript.sh
jim mcnamara 19 Junior Poster

Use the dd utility.

man dd

jim mcnamara 19 Junior Poster

accept() call fills in this structure with the address of the
connecting entity, as known to the underlying protocol. In the case
of AF_UNIX sockets, the peer's address is filled in only if the peer
had done an explicit bind() before doing a connect(). Therefore, for
AF_UNIX sockets, in the common case, when the peer had not done an explicit bind() before doing a connect(), the structure is filled with
a string of nulls for the address.

the address 0.0.0.0 is really all \0 chars