Sponsored Content
Homework and Emergencies Homework & Coursework Questions Need help creating shell script with output that has 2014 calendar and 2 text items from a"fortune" Post 302828321 by vbe on Tuesday 2nd of July 2013 09:06:56 AM
Old 07-02-2013
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 10:33 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filtering/Finding a "Fortune" message

Hi, I have had a problem in Linux with the "Fortune" messages (unfortunately! :( ) and I need to trap the message again. It starts with a "IMPORTANT NOTICE". To capture this, I write a script as follows.. #!/bin/sh a=0 while ; do /usr/games/fortune >> fortune.txt a=`expr $a + 1` done... (4 Replies)
Discussion started by: oldtrash
4 Replies

2. Shell Programming and Scripting

Q: Recording shell script screen output using "script" command ?

Hello, I need to capture everything showed on a screen by a shell script which needs user interaction. The shell script performs commads such as rsh so normal redirection to a file does not work. I know there is a special unix command call "script" which records screen session but the... (4 Replies)
Discussion started by: lalfonso.gomez
4 Replies

3. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

4. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

5. Virtualization and Cloud Computing

Creating VirtualBox-Image as "harddisk" by shell-script

Hello, I'm trying to create a VirtualBox "harddisk" and put an dd-image into it. This image shoudn't work as a virtual maschine, I just want to be able to mount it to an folder. How can I do this with an shell script? Sebi ---------- Post updated at 10:36 AM ---------- Previous update... (0 Replies)
Discussion started by: Sebi0815
0 Replies

6. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

7. Shell Programming and Scripting

Creating a Shortcut (to just type "l" but it runs "ls -lah")

How do I create shortcuts? For example: I just want to type one key "l" and have it output the command of "ls -lah" I believe it's creating a file called l with 755 permissions but I'm not sure where to put the file. *if it matters, I'm on a shared hosting web server using cPanel with... (2 Replies)
Discussion started by: ijustsawmars
2 Replies

8. Shell Programming and Scripting

What is the right way to redirect script output use ">" or ">>" ?

Which one of the following are more accurate and why? nohup myScript.sh 1>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh 1>>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh >nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh >>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 &... (3 Replies)
Discussion started by: kchinnam
3 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
All times are GMT -4. The time now is 10:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy