Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Question about a shell script and setting up an hdd for a linux based server


  • Please log in to reply
3 replies to this topic

#1 Eggsy

Eggsy

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Local time:11:57 PM

Posted 03 February 2017 - 08:56 AM

Hi there, 

 

I'm currently preparing for an exam and came across two question I'm having trouble with. I don't have access to my pc right now, so I can't test this stuff out myself and with no success in other forums, I hope to find some help here. 

 

1. The following Shell Script

myscript.sh
k=0
while read WORT
do
	echo $WORT|grep s>/dev/null || echo $WORT|grep r>/dev/null || let k=$k+1
done
echo $k

The script is then initated with the line:

ls | /home/notroot/scripts/myscript.sh

In the current directory are the following files: Asprin, Benz, Burroughs, Claremont, Eddings, Doms, Gardner, Lucas, Martin, McKiernam,

Pabst, Pratchett, Schlederer, Tolkien, Vollenbruch.
 
The Question: 
Which of the files lead to a change of the variable k.

And how often are the following statements invoked:

1."read WORT"
2. "echo $WORT|grep s>/dev/null"
3. "echo $WORT|grep r>/dev/null"
4. "let k=$k+1"
5. "echo $k"

 

My solution:

If I understand the script correctly, k would be increased every time the script comes across a file that contains at least one S and at least one R. So the files Asprin, Burroughs and Schlederer would lead to an increment of the variable k.

As for how often the statements are invoked:
1. 15 times
2. 7 times
3. 3 times
4. 3 times
5. Once

 

Did I unserstand the script correctly?

 

2. Setting up an HDD for a linux based video server

You want to set up a hard drive for a videoserver under linux. 

- The videofiles will have a size of at least 10MB and a maximum of 8GB.
- The hard drive has a disk space of 1TB.
- You can choose one of the following block sizes: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024kB.

 

The question:
Which block size do you choose for the filesystem and what's the maximum number of I-Nodes you would need. 

Additionally you also want to set up another filesystem for administrative data under the same conditions as above. The files have an average size of 150 Byte and the Filesystem is supposed to have a size of 100MB. Which block size do you choose?

 

My solution:

I have no idea how answer this exactly, but I suppose the maximum amount of i-nodes for a 1TB hard drive is around 31M since there's 1 i-node created for every 32KB of space. But as for the block sizes, I have no idea what to choose. I imagine 1MB would work to not fragment the files too much. 

 

Any help is much apprecaited. 

 

Thanks in advance and cheers!

 

 

 

 



BC AdBot (Login to Remove)

 


#2 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,420 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:06:57 PM

Posted 03 February 2017 - 10:35 AM

Welcome to BC Eggsy!

 

So I can't help on the second question..

 

Was just playing around with the script though. One thing I'm seeing that I can help with... for whatever reason I am currently lost on how many times the 'echo' statements are invoked.

 

You should be correct with 1 (read WORT) - 15 files so it goes through the loop 15 times.

Again 2 and 3 am getting lost for whatever reason right now.

4: so why do you think those 3 files iterate $k? The script is grepping for any file with r and s... catch my drift?

5: You are correct on that one.. pretty simple haha.

 

*Edit

 

Oh and your statement - " k would be increased every time the script comes across a file that contains at least one S and at least one R" - replace 'and' with 'or'. The || is an OR operator.


Edited by DeimosChaos, 03 February 2017 - 10:39 AM.

OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#3 Angoid

Angoid

  • Security Colleague
  • 299 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:East Midlands UK
  • Local time:11:57 PM

Posted 03 February 2017 - 11:16 AM

As I understand this line (which will be executed 15 times, one for each value that $WORT can take on):
 
echo $WORT|grep s>/dev/null || echo $WORT|grep r>/dev/null || let k=$k+1
The double-pipe symbol is a short-circuit OR. That is, if the first half returns true (non-zero) then the second half is ignored.
I'm not in front of a Linux box right now, but as I see it, here is what will happen:

Take the value of $WORT and look for any instance of the letter 's'. If present, send it to /dev/null and continue (else stop here).
Take the value of $WORT and look for any instance of the letter 'r'. If present, send it to /dev/null and continue (else stop here).
Now we know that both 's' and 'r' are present, increment k

Thus it's looking for the words that contain both the letters 'r' and 's'.

Man page for grep: https://linux.die.net/man/1/grep

It returns 0 (false) if the regular expression being checked for IS found (which causes it to continue to after the ||) or 1 (true) is the regular expression is NOT found.

Edited by Angoid, 03 February 2017 - 11:27 AM.

Helping a loved one through a mental health issue?  Remember ALGEE...

Assess the risk | Listen nonjudgementally | Give reassurance and info | Encourage professional help | Encourage self-help and support network

#4 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,420 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:06:57 PM

Posted 03 February 2017 - 11:43 AM

As I understand this line (which will be executed 15 times, one for each value that $WORT can take on):
 

That was what I was thinking... but it was throwing me for some reason.

 

*Edit

 

Oh, actually I know why it was throwing me. The question asks how many times each of the individual parts of that line are executed.

 

So I believe OP, that you are correct when you say 7 and 3 for those two grep commands.The first one hits on 7, then the next one hits on 10 leaving a difference of 3.


Edited by DeimosChaos, 03 February 2017 - 11:54 AM.

OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users