Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:34:08+00:00 2026-05-24T16:34:08+00:00

I’ve written a script for me to start and stop my Perforce server. To

  • 0

I’ve written a script for me to start and stop my Perforce server. To shutdown the server I use the kill -SIGTERM command with the PID of the server daemon. It works as it should but there are some discrepancies in my script concerning the output behavior.

The script looks as follows:

#!/bin/sh -e

  export P4JOURNAL=/var/log/perforce/journal
  export P4LOG=/var/log/perforce/p4err
  export P4ROOT=/var/local/perforce_depot
  export P4PORT=1666

  PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

  . /lib/lsb/init-functions

  p4start="p4d -d"
  p4stop="p4 admin stop"
  p4user=perforce

  case "$1" in
  start)
    log_action_begin_msg "Starting Perforce Server"
    daemon -u $p4user -- $p4start;
    echo "\n"
    ;;

  stop)
    echo "BLABLA"
    echo "$(pidof /usr/local/bin/p4d)"
    #daemon -u $p4user -- $p4stop;
    p4dPid="$(pidof /usr/local/bin/p4d)"
    echo $p4dPid
    if [ -z "$(pidof /usr/local/bin/p4d)" ]; then
      echo "ERROR: No Perforce Server running!"
    else
      echo "SUCCESS: Found Perforce Server running!\n\t"
      echo "Shutting down Perforce Server..."
      kill -15 $p4dPid;
    fi
    echo "\n"
    ;;

  restart)
    stop
    start
    ;;

  *)
    echo "Usage: /etc/init.d/perforce (start|stop|restart)"
    exit 1
    ;;

esac

exit 0

When p4d is running the stop block works as intended, but when there is no p4d running the script with stop only outputs BLABLA and an empty new line because of the echo "$(pidof /usr/local/bin/p4d)". The error message stating that no server is running is never printed. What am I doing wrong here?

PS: The part if [ -z "$(pidof /usr/local/bin/p4d)" ]; then has been changed from if [ -z "$p4dPid" ]; then for debug reasons.

EDIT: I narrowed down the problem. If I don’t use the p4dPid variable and comment out the lines p4dPid="$(pidof /usr/local/bin/p4d)" and echo $p4dPid the if block is processed and the error messages is printed. Still I don’t unterstand what is causing this behavior.

EDIT 2: Problem solved!

The -e in #!/bin/sh -e was causing the shell to exit the script after any statement returning a non-zero return value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:34:09+00:00Added an answer on May 24, 2026 at 4:34 pm

    Problem solved!

    The -e in #!/bin/sh -e was causing the shell to exit after any statement returning a non-zero return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.