Need help creating shell script with output that has 2014 calendar and 2 text items from a"fortune" | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Need help creating shell script with output that has 2014 calendar and 2 text items from a"fortune"

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-01-2013
dandanhelpmeman dandanhelpmeman is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 30 July 2013, 3:08 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Code Need help creating shell script with output that has 2014 calendar and 2 text items from a"fortune"

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

I am required to create a bash shell script with either emacs or vi. It must include the year 2014 calendar on the left side and two text items on the right side.

2. Relevant commands, code, scripts, algorithms:

the two text items are from what my professor describes as a "fortune server". I have two commands to query them. nc langley.cs.fsu.edu 19000 and " " 19001. I am also instructed that the 2014 calendar must be computed and not a fixed value of 2014. I am told to use d=`date '+%Y'` to get the current year, then told to use the Bash syntax $((++d)). I am then recommended to use pr to paste the output together with pr -t -T -m -w 140 file1 file2.


3. The attempts at a solution (include all code and scripts):
It seems to take the d=`date '+%Y'` but then when i go to Bash and type $((++d)) it says 2014:command not found.
I also don't understand how to paste the two text items into individual files in order to put them together in a single script



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

FSU,Tallahassee, FL, USA, Langley, COP3353

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Sponsored Links
    #2  
Old 07-02-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 September 2014, 4:43 AM EDT
Location: Switzerland - GE
Posts: 5,710
Thanks: 156
Thanked 400 Times in 375 Posts
hint:

Code:
n12:/home/vbe/bash $ d=`date '+%Y'`
n12:/home/vbe/bash $ echo $d
2013
n12:/home/vbe/bash $ echo $((++d))
2014

typing $((++d)) is asking the shell to execute the value, 2014 is not a command...
Sponsored Links
    #3  
Old 07-02-2013
dandanhelpmeman dandanhelpmeman is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 30 July 2013, 3:08 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Update

So does that mean I have to input the d=`date '+%Y'` into emacs? Also once it's in emacs am I supposed to be putting parentheses around the commands to make them work?

Also here is a link to the assignment, this was left off of the original post.

www dot cs dot fsu dot edu slash ~langley slash COP3353 slash 2013-2 slash Assignment02 dot html

(Had to add "dot" "slash" since I'm too noob to post urls, sorry)
    #4  
Old 07-02-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 September 2014, 4:43 AM EDT
Location: Switzerland - GE
Posts: 5,710
Thanks: 156
Thanked 400 Times in 375 Posts
Well we are not going to do the work for you, you know that hum...
You seem to be quite lost ( were you listening during the course? ...) English is a second language for me so Im very cautious when it comes to understand assignments... not the same thing as to solve issues...
My understanding is that you are NOT to put in your shell script what you think but it is the expected output of the execution of your script: Not the same thing...
So the script you are to write has to produce for output the claendar 2014 on the left and the output of 2 files on the right,the pr code sample is a sample to me ... you may need to adapt...

Last edited by vbe; 07-02-2013 at 09:03 AM.. Reason: typos sorry i thinkmy dislexya is playing with me again...
Sponsored Links
    #5  
Old 07-02-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 September 2014, 4:43 AM EDT
Location: Switzerland - GE
Posts: 5,710
Thanks: 156
Thanked 400 Times in 375 Posts
bash isnt necessary but recommended by your instructor ( I still use ksh or true sh ...)
and I use vi...
this is the wanted output:

Code:
 Your shell script should create output that looks like this:


                               2014                                    _________________________________________
                                                                      / Be careful of reading health books, you \                                      
       January               February                 March           | might die of a misprint.                |
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa    |                                         |
          1  2  3  4                      1                      1    \ -- Mark Twain                           /
 5  6  7  8  9 10 11    2  3  4  5  6  7  8    2  3  4  5  6  7  8     -----------------------------------------
12 13 14 15 16 17 18    9 10 11 12 13 14 15    9 10 11 12 13 14 15            \   ^__^
19 20 21 22 23 24 25   16 17 18 19 20 21 22   16 17 18 19 20 21 22             \  (oo)\_______
26 27 28 29 30 31      23 24 25 26 27 28      23 24 25 26 27 28 29                (__)\       )\/\                                                     
                                              30 31                                   ||----w |
        April                   May                   June                            ||     ||
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
       1  2  3  4  5                1  2  3    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    4  5  6  7  8  9 10    8  9 10 11 12 13 14
13 14 15 16 17 18 19   11 12 13 14 15 16 17   15 16 17 18 19 20 21     _________________________________________
20 21 22 23 24 25 26   18 19 20 21 22 23 24   22 23 24 25 26 27 28    / If one cannot enjoy reading a book over \                                      
27 28 29 30            25 26 27 28 29 30 31   29 30                   | and over again, there is no use in      |
                                                                      | reading it at all.                      |
        July                  August                September         |                                         |
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa    \ -- Oscar Wilde                          /
       1  2  3  4  5                   1  2       1  2  3  4  5  6     -----------------------------------------
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    7  8  9 10 11 12 13       \                                                                             
13 14 15 16 17 18 19   10 11 12 13 14 15 16   14 15 16 17 18 19 20        \                                                                            
20 21 22 23 24 25 26   17 18 19 20 21 22 23   21 22 23 24 25 26 27            .--.
27 28 29 30 31         24 25 26 27 28 29 30   28 29 30                       |o_o |
                       31                                                    |:_/ |
       October               November               December                //   \ \                                                                   
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa         (|     | )
          1  2  3  4                      1       1  2  3  4  5  6        /'\_   _/`\                                                                  
 5  6  7  8  9 10 11    2  3  4  5  6  7  8    7  8  9 10 11 12 13        \___)=(___/
12 13 14 15 16 17 18    9 10 11 12 13 14 15   14 15 16 17 18 19 20
19 20 21 22 23 24 25   16 17 18 19 20 21 22   21 22 23 24 25 26 27
26 27 28 29 30 31      23 24 25 26 27 28 29   28 29 30 31
                       30

Here are some tools that you can use to do the assignment:

The left hand side is generated by the program cal.
The two text items on the right hand side are from a "fortune server" that you can query at nc langley.cs.fsu.edu 19000 and at nc langley.cs.fsu.edu 19001.
To create names for temporary files, you can use the program mktemp.
To get the current year, you can use d=`date '+%Y'`; to increase the year, you can use the Bash syntax $((++d))
To paste the output together horizontally from these programs, I recommend using pr (and not paste) like pr -t -T -m -w 140 file1 file2


This is your instructor's "pseudocode" on how he wrote the script, and so what you are asked to write:

Code:
#!/bin/bash



#
# Do calendar bits
#

  # Create a temporary file for the calendar.
  # Get the year from "date".
  # Increase the year by one and then call the "cal" program with that year. Write the
  # output to the temporary calendar file.


#
# Do fortune bits
#

  # Create a temporary file to hold both of the "fortunes".
  # Collect first fortune from the fortune server at 19000 and put it in the fortune temporary file.
  # Collect second fortune from the fortune server at 19001 and append it to the fortune temporary file.


#
# Now use "pr" to push everything together (see Assignment02 guidlines), and output everything to stdout
#



#
# Remove temporary files and exit
#

exit 0

You have now ( and we also hehe...) all the information needed to do the given task, start by copying this script, it will serve you as template and documentation, try to write the calendar part, as written:
# Create a temporary file for the calendar.
# Get the year from "date".
# Increase the year by one and then call the "cal" program with that year. Write the
# output to the temporary calendar file.

Show us the result, then if OK we pass to the next part...

Quote:
I have two commands to query them:
nc langley.cs.fsu.edu 19000 and " " 19001.
the output of the command is to be saved as file1 file2 for the right side output of your script...

Last edited by vbe; 07-02-2013 at 09:33 AM..
Sponsored Links
    #6  
Old 07-02-2013
dandanhelpmeman dandanhelpmeman is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 30 July 2013, 3:08 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Yes I don't expect anyone to do the work for me. I was adding the link since I thought I was explaining the assignment poorly. I am quite lost, the professor assumes everyone knows how to do basic commands to start but I don't. I am not a computer science student. This was supposed to be an easy elective class, boy they fooled me! Thanks anyways for the attempt to help. I think I'll just try and see what happens.
Sponsored Links
    #7  
Old 07-02-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 September 2014, 4:43 AM EDT
Location: Switzerland - GE
Posts: 5,710
Thanks: 156
Thanked 400 Times in 375 Posts
Look at my updated last post:
Start by doing the calendar part:
When you dont know what to do, you try simple instructions... look at my first post thenlook at the output of cal 2013 doesnt that inspire you? Do you see now the reason of the temporary file ? ( save the output...)
Get that working and we will see next step...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating VirtualBox-Image as "harddisk" by shell-script Sebi0815 Virtualization and Cloud Computing 0 03-10-2010 10:36 AM
"too big" and "not enough memory" errors in shell script jerardfjay AIX 11 03-16-2009 11:09 PM
read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell wiseguy Shell Programming and Scripting 9 01-28-2009 12:20 PM
Q: Recording shell script screen output using "script" command ? lalfonso.gomez Shell Programming and Scripting 4 01-18-2007 08:31 PM
Filtering/Finding a "Fortune" message oldtrash Shell Programming and Scripting 4 05-13-2005 07:16 AM



All times are GMT -4. The time now is 05:32 AM.