Welcome to the Linux Foundation Forum!

Lab 4.1 fake_service.txt

The fake_service.txt on the 4.1 Lab download link has messed up formatting. I reformatted and attached in case anyone else needs it.

Or copy/paste from here if you wish:

#!/bin/bash
# fake_service
# Starts up, writes to a dummy file, and exits
#
# chkconfig: 35 69 31
# description: This service doesn't do anything.
# Source function library

. /etc/sysconfig/fake_service

case "$1" in
start) echo "Running fake_service in start mode..."
touch /var/lock/subsys/fake_service
echo "$0 start at $(date)" >> /var/log/fake_service.log
if [ ${VAR1} = "true" ]
then
echo "VAR1 set to true" >> /var/log/fake_service.log
fi
echo
;;
stop)
echo "Running the fake_service script in stop mode..."
echo "$0 stop at $(date)" >> /var/log/fake_service.log
if [ ${VAR2} = "true" ]
then
echo "VAR2 = true" >> /var/log/fake_service.log
fi
rm -f /var/lock/subsys/fake_service
echo
;;
*)
echo "Usage: fake_service {start | stop}"
exit 1
esac
exit 0

Comments

  • ultraninjaultraninja Posts: 20
  • coopcoop Posts: 730
    I can't find anything wrong with the script. If you could be specific, it will be possible to evaluate your comment. The script in the class works fine where tested.
    You have to say exactly what is wrong with formatting. When people cut and paste off pdf's the pdf reader sometimes screws up (in particular acroread screws up underscores and special characters, use a real pdf reader like evince please :) )
  • ultraninjaultraninja Posts: 20
    My apologies for not being specific. Perhaps I'm doing something wrong but it appears there aren't newline characters in the file, causing the entire script to be one single line.
    [[email protected] ~]$ wget https://lms.360training.com/scorm/linuxfoundation/LFS201/fake_service.txt
    --2015-05-12 10:51:32--  https://lms.360training.com/scorm/linuxfoundation/LFS201/fake_service.txt
    Resolving lms.360training.com (lms.360training.com)... 207.207.3.60
    Connecting to lms.360training.com (lms.360training.com)|207.207.3.60|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 778 [text/plain]
    Saving to: ‘fake_service.txt’
    
    100%[========================================================>] 778         --.-K/s   in 0s      
    
    2015-05-12 10:51:32 (153 MB/s) - ‘fake_service.txt’ saved [778/778]
    
    [[email protected] ~]$ cat fake_service.txt 
    #!/bin/bash# fake_service# Starts up, writes to a dummy file, and exits## chkconfig: 35 69 31# description: This service doesn't do anything.# Source function library. /etc/sysconfig/fake_servicecase "$1" in start) echo "Running fake_service in start mode..."   touch /var/lock/subsys/fake_service   echo "$0 start at $(date)" >> /var/log/fake_service.log   if [ ${VAR1} = "true" ]   then     echo "VAR1 set to true" >> /var/log/fake_service.log   fi   echo   ;; stop)  echo "Running the fake_service script in stop mode..."  echo "$0 stop at $(date)" >> /var/log/fake_service.log  if [ ${VAR2} = "true" ]  then      echo "VAR2 = true" >> /var/log/fake_service.log  fi  rm -f /var/lock/subsys/fake_service  echo  ;;*)  echo "Usage: fake_service {start | stop}"  exit 1esacexit 0[[email protected] ~]$
    
    
  • coopcoop Posts: 730
    Yes you right :( I have confirmed it. It seems the online platform converted to Windows end of line characteristics (old problem). There are 3 other download files in the course (writeit.c signals.c ioscript.sh) that are affected as well, but while they have changed end of line characters, they look ok. We'll get them fixed in the next release.

    There doesn't seem to be a way to post a file here in the forum (probably wise) but if you go to http://training.linuxfoundation.org/cm/LFS201, and log in with: username LFtraining password: Penguin2014, you can download all the files directly.

  • ultraninjaultraninja Posts: 20
    Thanks Jerry. I've logged in and grabbed the files in preparation for those upcoming labs.
  • I downloaded the script for lab 4.1 from the link provided by Jerry and it worked. But I still don't understand why the script won't work when downloading from the class directly. I thought it was because there were windows newline characters hiding somewhere inside the script but after running dos2unix, it still doesn't work. Does anyone know why this doesn't work? How would you go about fixing the script (other than downloading a fresh copy from Jerry's link)?
  • coopcoop Posts: 730
    The file is broken, it is not worth figuring out. I thought it was fixed in the class but it wasn't, we'll try and take care of it.
  • FToledanoFToledano Posts: 27
    edited February 2016
    Hi Brucecurcio,

    I waste 3 hours with this problem. The script code in the link of the 4.1 Lab in the spanish course is also unformated. If a copy/paste of the text in the pdf is performed, service utility throws that the file /etc/init.d/fake_service not exist, but the file is well placed and chkconfig shows the service in the correct runlevels. Some character must be hidden in the text and the file gives errors with service utility.

    A way to fix the copied text from the pdf is the dos2unix utility.
    dos2unix name_of_the_corrupted_file
    

    Once the file is well formatted the script runs without problems.

    Would if be possible for the moderators to write a sticky post in the forum with the corrections to the material on each lesson?. It will be very hepfull.

    Thanks!
  • FToledano wrote:
    Hi Brucecurcio,

    I waste 3 hours with this problem. The script code in the link of the 4.1 Lab in the spanish course is also unformated. If a copy/paste of the text in the pdf is performed, service utility throws that the file /etc/init.d/fake_service not exist, but the file is well placed and chkconfig shows the service in the correct runlevels. Some character must be hidden in the text and the file gives errors with service utility.

    A way to fix the copied text from the pdf is the dos2unix utility.
    dos2unix name_of_the_corrupted_file
    

    Once the file is well formatted the script runs without problems.

    Would if be possible for the moderators to write a sticky post in the forum with the corrections to the material on each lesson?. It will be very hepfull.

    What do you mean by "Sticky post in this forum"? If you experience a problem with one of your course materials, create a post under the related thread and past the material with all components there. Someone should be able to help as Jerry did.
    Thanks!
  • coopcoop Posts: 730
    This was corrected (at least in the English version) last summer, and in this very thread there is a link to a web site (at training.linuxfoundation.org) where you can download a perfect copy without the dos2unix conversion. Furthermore, when I download the script from the download button it is also fine. If it is not, it is because you are downloading under Windows and it is doing a unix->dos conversion on you, which we can't do anything about. Furthermore, in the description of the exercise the actual full text of the script is there, and you can simply cut and paste it (in any language).

    Unfortunately, when you use Windows programs (such as some browser downloads and pdf viewers such as acroread) these kinds of problems can occur as they try to "improve" upon unix customs.

    As far as "stick notes" go, we update the course frequently to fix minor problems such as these and as long as we don't introduce new material or make more substantive changes you won't even notice.
  • FToledanoFToledano Posts: 27
    edited February 2016
    Thank you Istimsak and coop for the responses.

    First of all I want to said that english is not my native language, I apologize for the errors. Thank you again for your patience and help.

    All the browsers I use for this course are under Archlinux.

    I'm enrolled in the LFSE spanish course and the material is not corrected yet. At this moment the lab 2.1 code link tested with Chrome, Firefox and QupZilla, seems like that:
    #!/bin/bash# fake_service# Starts up, writes to a dummy file, and exits## chkconfig: 35 69 31# description: This service doesn't do anything.# Source function library. /etc/sysconfig/fake_servicecase "$1" in start) echo "Running fake_service in start mode..."   touch /var/lock/subsys/fake_service   echo "$0 start at $(date)" >> /var/log/fake_service.log   if [ ${VAR1} = "true" ]   then     echo "VAR1 set to true" >> /var/log/fake_service.log   fi   echo   ;; stop)  echo "Running the fake_service script in stop mode..."  echo "$0 stop at $(date)" >> /var/log/fake_service.log  if [ ${VAR2} = "true" ]  then      echo "VAR2 = true" >> /var/log/fake_service.log  fi  rm -f /var/lock/subsys/fake_service  echo  ;;*)  echo "Usage: fake_service {start | stop}"  exit 1esacexit 0
    

    Istimsak :
    What do you mean by "Sticky post in this forum"?

    As I refer previously, english is not my native language, I want to mean something like this:

    Stickying

    As is mentioned in other moderation messages, the material corrections can't be done "at the moment" because some reasons, and I only wanted to suggest that a post in the top of the forum showing this issues may be helpfull, something like:
    Corrections:
    Lesson ......
    Lesson 4
    - If you experienced problems with the text showed in LAB 2.1 script code, download it from this site .......... (or whatever you want to explain or correct).
    Lesson 5
    etc.
    
    All people would see this post before read the lesson and to be prevented.

    As you said, we can post questions in the forum but when I experienced problems trying to run service fake_service start, the first I thinked is that I was doing something wrong even more so when running chkconfig the fake_service appears ok and in the correct runlevels. After repeat the process a lot of times and read the lesson again several times I decide to test formating the file with dos2unix and all works ok.

    After that I visit the forum to post it, but all was commented in this post. I added my comment yesterday only to show Brucecurcio user that after copy/paste the pdf code and formating the file with dos2unix utility, service can read the file without problems.

    I try not to bother anyone, the sticky post was only a suggestion because the original post with the problem is dated from 2015 summer and the material in the spanish course isn't corrected yet. I thinked (because moderators have said it in others posts) that the correction of the material is not an easy task and this can help.

    coop wrote:
    As far as "stick notes" go, we update the course frequently to fix minor problems such as these and as long as we don't introduce new material or make more substantive changes you won't even notice.


    As I said, I try to run the course under 3 different browsers included chrome under archlinux and other linux distros and seems that spanish course, at least for the LAB 2.1, isn't be updated.

    In relation with the new material for the exam, are being applied the changes to the spanish course? If someone post some of them I can check it.

    Thank you again.
  • FToledano wrote:

    As I refer previously, english is not my native language, I want to mean something like this:

    Stickying

    As is mentioned in other moderation messages, the material corrections can't be done "at the moment" because some reasons, and I only wanted to suggest that a post in the top of the forum showing this issues may be helpfull, something like:
    Corrections:
    Lesson ......
    Lesson 4
    - If you experienced problems with the text showed in LAB 2.1 script code, download it from this site .......... (or whatever you want to explain or correct).
    Lesson 5
    etc.
    
    All people would see this post before read the lesson and to be prevented.

    As you said, we can post questions in the forum but when I experienced problems trying to run service fake_service start, the first I thinked is that I was doing something wrong even more so when running chkconfig the fake_service appears ok and in the correct runlevels. After repeat the process a lot of times and read the lesson again several times I decide to test formating the file with dos2unix and all works ok.

    After that I visit the forum to post it, but all was commented in this post. I added my comment yesterday only to show Brucecurcio user that after copy/paste the pdf code and formating the file with dos2unix utility, service can read the file without problems.

    I try not to bother anyone, the sticky post was only a suggestion because the original post with the problem is dated from 2015 summer and the material in the spanish course isn't corrected yet. I thinked (because moderators have said it in others posts) that the correction of the material is not an easy task and this can help.

    Well, if we can created a new thread under this forum category, and update it with new material by editing the original post, it would seem possible. Perhaps an article or blog might be better with permanent link added to this thread.
Sign In or Register to comment.