Why doesn't this work (sh) and what's the (t)csh version?

Why doesn't this work (sh) and what's the (t)csh version?

Post by Don Faulkn » Fri, 17 Apr 1992 13:47:08



Ok, here's the scoop: I'm running screen and need to see at each login
if it's already running. I tried this:

scr = ps | grep -c screen
if ( $scr >= 2 ) then
   #screen is running (1 for screen, 1 for grep screen)
   #so ignore the rest
fi

What's the problem? I'm lost. BTW, I'm just a *little* unfamillar with
shell programming, but this is the only way (it goes in either .cshrc
or .login). Also, what do I need to do to get this sort of thing to work
under tcsh?

Furthermore, if screen is not running, I want to resume a detached
screen if one exists. If not, I want to start screen. If screen is running
do nothing. Here's a synopsis:

IF NOT screen_running DO:
   Attempt to resume screen
   if resume fails
      start screen
   endif
endif

alternatively,

if screen not running,
   if detached screen exists ;(check ~.screen/ ?)
      start it
   else
      start screen
   endif
endif

Any ideas would be *GREATLY* appreciated.

                                   Many thanks,
                                   Don Faulkner

--
*******************************************************************************
| Donald Faulkner         | Only on    // /\       _   _         __           |



*******************************************************************************

 
 
 

Why doesn't this work (sh) and what's the (t)csh version?

Post by John Navar » Sat, 18 Apr 1992 05:15:18



>Ok, here's the scoop: I'm running screen and need to see at each login
>if it's already running. I tried this:

>scr = ps | grep -c screen
>if ( $scr >= 2 ) then
>   #screen is running (1 for screen, 1 for grep screen)
>   #so ignore the rest
>fi

>Any ideas would be *GREATLY* appreciated.

        Well, here's an idea: why don't you just test the exit status
of 'screen -r'? If if comes back and says, "there is no screen to be
resumed" then you obviously aren't running screen so you can just
issue a screen command and foregot the ps | grep stuff.
        A problem arises if you are already attached to a screen. Screen
-r won't reattach to an already attached screen so what I usually do
when this happens is issue a "kill -HUP pid" and then a screen -r and
things work out then. You can deal with thing scenario in some manner.

I don't have time to be more explicit with the coding right now so
if you can't figure this out, let me know and I will try writing some
script to do it.

-tms

--
From the Lab of the MaD ScIenTiST:



 
 
 

Why doesn't this work (sh) and what's the (t)csh version?

Post by Richard Pieri/Stainless Steel R » Sat, 18 Apr 1992 11:10:14


def2> Ok, here's the scoop: I'm running screen and need to see at each login
def2> if it's already running. I tried this:

[worthless code]

def2> What's the problem? I'm lost. BTW, I'm just a *little* unfamillar
def2> with shell programming, but this is the only way (it goes in either
def2> .cshrc or .login). Also, what do I need to do to get this sort of
def2> thing to work under tcsh?

Ok. There are two possibilites 1) screen has a detached process you wish
to reconnect to, 2) no screen process running. In C-Shell:

ps x | grep -i '[0-9] screen' >/dev/null
if ( $status == 0 ) then
    screen -r   # resume screen
else
    screen      # start screen
endif

I use something almost identical to this in my .login (but with a small
perl script that asks before starting screen up--the script isn't mine, so
I can't really post it).

--Rat
--
||||| | | | |  |  |  |   |   |    |    |    |   |   |  |  |  |  | | | | | |||||
                                                   __        ___
Richard Pieri, Northeastern's Stainless Steel Rat/   | /| / /   | The Worlds

    UUCP: ...!northeastern.edu!splinter!ratinox/   | /| / / / | | Association:

  USNail: 14 Westdale RD  Holbrook, MA 02343 /   | /| / / /___| | any problem
 ICBMnet: 42 deg 1 min N, 71 deg 0 min W    /    |/ |/ /_//_____| for you.

 
 
 

Why doesn't this work (sh) and what's the (t)csh version?

Post by John Navar » Sat, 18 Apr 1992 12:28:59




>Ok. There are two possibilites 1) screen has a detached process you wish
>to reconnect to, 2) no screen process running. In C-Shell:

        Actually, there are 3 possibilities I can think of right now:
1) screen is not running 2) screen has a detached process 3) screen
has an attached process that you somehow got disconnected from.

just testing for 1 and 2 will not always work. 3 happens to me sometimes
when my modem line gets disconnected, computer screws up and I need to
reboot, etc.

My rough idea (which I have not tested yet) is the following:
sh:
        noresponse=`screen -r | grep No`
        if ($noresponse)        #screen is not running
                screen
        fi
        attached=`screen -r | grep Attached`
        if ($attached)          # there is already an attached screen
                # do some correcting for that
                pid=`ps | grep screen | 'something to get pid field'`
                kill -HUP $pid
                screen -r
        else    
            # there is a detached screen to connect to
            screen -r  
        fi

That is the basic idea and you can transform it to yucky csh or whatever
you wish.

-tms

--
From the Lab of the MaD ScIenTiST:


 
 
 

1. sh/csh doesn't exit...why?

Howdie,
can anybody send me some enlightments about the following
happening on a sun (SunOS 4.1.2) with csh (sh too):
(the dotted ... sections are from the csh man page)

I thought 'exit' would terminate the shell.
  ...
  Built-In Commands
  ...
     exit [ (expr) ]
               The shell exits, either  with  the  value  of  the
               status  variable,  or with the value of the speci-
               fied by the expression expr.
  ...
  OPTIONS
  ...
     -f   Fast start. Read  neither  the  .cshrc  file,  nor  the
          .login file (if a login shell) upon startup.
  ...
     -s   Take commands from the standard input.

Now consider csh running in a pipe:
(to help reading, I enclosed what I typed in < >)
trial% cat | csh -f -s
<exit>
<ls>
file1  file2  file3
<set>
argv  ()
cwd   /home/swing/ralf/si/horst-k/tmp
home     /home/swing/ralf
...(lots of more stuff deleted)
<^D>
trial% ls
file1  file2  file3

WHY does the 'exit' not exit?  Definitely it's not a flushing
problem, because the 'ls' and 'set' is executed.  Since 'exit' is a
built-in, it shouldn't invoke a subshell, shouldn't it?  If the
shell is started interactively, exit exits :-)

Any email-enlightments welcome.
Regards
Ralf
--
----

Reads mail.
Some Plan.

2. network card led

3. Why "$ read name < file_name" doesn't work in sh script ?

4. Can anyone help with this?

5. Why doesn't this work in csh?

6. X resolution problem

7. why preinst.sh doesn't work?

8. POP3 problem

9. Summary of why csh doesn't work for root login

10. Why doesn't this csh command work on HP-UX 10.20???

11. Why doesn't var=`umask` work in sh?

12. Why doesn't \c work in sh/ksh echo on Suns?

13. why doesn't this work on Ultrix bourne sh?