UNIX commands and scripts


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX commands and scripts
# 1  
Old 04-23-2019
UNIX commands and scripts

Hi guys,

Hoping someone can help with the below - involves basic commands and some scripting. Thanks so much in advance for your amazing time and help.

3. The file /etc/profile contains the default initialization options for your shell.
Produce a unique list of all variables with uppercase names that have been set
in /etc/profile sorted in alphabetical order.

the output should be something like:

Code:
EUID
HISTCONTROL
HISTSIZE
HOSTNAME
LOGNAME
MAIL
PATH
UID
USER

4. The file /etc/passwd contains lines that look like this:

Code:
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin

The field delimiter is : and the fields are:

Code:
username:password:userid:groupid:realname:homedirectory:shell

Come up with a UNIX command that will find and print out the home directory of
the user whose username is 'root'.

5. Come up with a UNIX command that will print a sorted, unique list of all of
the different shells used by the different users in /etc/passwd.

6. Come up with a UNIX command that will print a list of usernames from /etc/passwd
that end with a vowel.

7. The 'env' command prints out all of the environment variables and their values.
Come up with a command that prints a list of environment variables whose names
end with either 'NAME', 'DIR' or 'PATH'.

8. Write a script called 'home.sh' which takes a username as its argument and
will print out the home directory of that user as follows:

Code:
$ ./home.sh root
root's home directory is /root
$ ./home.sh nobody
nobody's home directory is /

If the command is used incorrectly, print a usage error to stderr:

Code:
$ ./home.sh
Usage: ./home.sh username

9. Write a script called big which takes a filepath as an argument. The script
should print "Big" if the file is more than 1000 bytes or "Small" if the file
is less than 1000 bytes. If exactly one argument was not given, print "Error"
to stderr.

10. Using the metric system, where 1 kilobyte = 1000 bytes, write a script that
takes a filename as an argument and prints out the file size in kilobytes by
dividing the number of bytes by 1000.
# 2  
Old 04-23-2019
Kindly do not post classroom or homework type of problems in the main forums.

Homework and coursework-related questions should only be posted in this forum using a special homework template.

Discussed with the new member in Live Chat.

Thank You.

The UNIX and Linux Forums.

REF: Here is a part of the Live Chat on this with the new member:

Image
These 2 Users Gave Thanks to Neo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Saltstack commands inside bash scripts donā€™t work

In a Redhat Linux environment, I could run salt commands on the $ prompt but not inside my bash scripts. It will say command not found and the $PATH variable is exactly the same outside and inside the script. !#/usr/bin/bash echo “running”¯ salt "*" cmd.run ‘ls' exit Output:-... (8 Replies)
Discussion started by: gurudewa
8 Replies

2. UNIX for Dummies Questions & Answers

Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts

I have a shell script which executes to write html codes into a text file. My next step is to email the text file so that receiving person (people who i send email to) should be able to see pie/chart or bar graph (whatever i design in my code) in their email. Following is the example of a sample... (7 Replies)
Discussion started by: bikerboy
7 Replies

3. Homework & Coursework Questions

Calculating Total and Averages with awk Commands & Scripts

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: Write an awk script(company.awk) for the workers file to find the number of workers of each departman, total... (8 Replies)
Discussion started by: RedJohn
8 Replies

4. Homework & Coursework Questions

1st yr Exam revision thread - Scripts, C, Commands

Hello, I have an exam for 1st year Linux and Unix programming coming up in a week and I need some help going over the past exams, I want to make sure I'm getting the right answers in the past exams to ensure full marks. The internet is a distraction so making this thread will hopefully help me... (3 Replies)
Discussion started by: murphy
3 Replies

5. Shell Programming and Scripting

Bash scripts as commands

Hello, the bulk of my work is run by scripts. An example is as such: #!/bin/bash awk '{print first line}' Input.in > Intermediate.ter awk '{print second line}' Input.in > Intermediate_2.ter command Intermediate.ter Intermediate_2.ter > Output.out It works the way I want it to, but it's not... (1 Reply)
Discussion started by: Leo_Boon
1 Replies

6. Shell Programming and Scripting

writing shell scripts of commands

can anyone help me in writing a shell script to visualize how simple commands work and on what logic. For Eg: ls command how it lists out all the files and directories, need to write a simple script based on the commands source code.:D (0 Replies)
Discussion started by: rahul_11d
0 Replies

7. Shell Programming and Scripting

[PERL] Running unix commands within Perl Scripts

I understand that in order to run basic unix commands I would normally type at the prompt, I would have to use the following format system(ls -l); or exec(ls -l); But when I actually try to use the command, the script fails to compile and keeps telling me there is an error with this line. ... (1 Reply)
Discussion started by: userix
1 Replies

8. Shell Programming and Scripting

Running shell scripts automatically without using Batch or at commands

I have been trying to run a unix script which contains many sql statements.I need to run this script every monday morning. I tried to run on command prompt, it works fine. But while I run it via batch or at command., it returns with library module could not be loaded (libcompat.1.o could not be... (3 Replies)
Discussion started by: ritzwan0
3 Replies

9. UNIX for Advanced & Expert Users

Porting of Windows written unix scripts to unix platform

Can anybody help me in finding out a solution for the problem below? When we write .unix or .sh files in windows OS and port them to Unix platforms there is a character ^M inserted at the end of each line of the script file. During ftp porting I set the transfer mode as ASCII for the script... (7 Replies)
Discussion started by: tamilselvi
7 Replies

10. UNIX for Dummies Questions & Answers

Maingrame to UNIX sending UNIX commands

I want to know if there is a way to send unix commands thru FTP from a mainframe to kick off Autosys Jobs. I just need to send a command from the mainframe to UNIX and have UNIX execute that command. (2 Replies)
Discussion started by: skammer
2 Replies
Login or Register to Ask a Question