Shell Scripts

I am taking a Linux class and am doing horribly, I just do not understand Linux. Can anyone please tell me how to create a shell script containing the `echo`, `whoami`, `groups`, and `pwd` commands?

I can do these as individual commands but cannot figure out how to do this in a shell script and get the output to produce output similar to the following:

You a
root
You are a member of the following groups:
root bin daemon sys adm disk wheel
Your current working directory is:
/tmp

My hair is getting thinner and grayer because of this.. Please help!


Similar Content



What Exactly Is PATH

books say that PATH variable contains the locations where the shell searches the commands to execute them.

I created a shell script and saved it in /home/user/Downloads directory and then i ran this script from the /home/user/Downloads directory. It did not execute.

however when i did set the path
export PATH=$PATH:/bin/sh within /home/user/Downloads directory, the shell script executed. Does it not mean that PATH variable is holding the locations of the shell program rather than the commands that are to be executed?

everytime i have to give the location of the shell i.e /bin/sh in the PATH variable no matter from where i am executing my script

Sending SMB Client Commands Through Shell Script

Hello.

I have a shell script, which I am using to access the SMB Client:

Code:
#!/bin/bash
cd /home/username
smbclient //link/to/server$ password -W domain -U username
recurse
prompt
mput baclupfiles
exit

Right now, the script runs, accesses the server, and then asks for a manual input of the commands.

Can someone show me how to get the commands:
Code:
recurse, prompt, mput baclupfiles and exit

to be run by the shell script please?

How To Run Shell Script In Any Folder Except The Folder Which Contains The Shell Script

I am using a shell script named by test.sh, for example containing
Code:
address="$PWD"
echo "$address"

.
If I put it in folder temp1, and run test.sh, then it will give me the address of the current directory. But if I am now in folder temp2, and I want to run test.sh, I always need to copy test.sh to folder temp2, and then run it. Is there a way that I can run test.sh without copying it? I am not root user.

Need Help To Get The Available Hosts Among Many Hosts

I have many hosts as following. But those hosts are dual operating system (Linux and Windows). I always run program background. If someone is using Linux, it is fine. But if someone is using windows or the host is offline. Then, I cannot use ssh. The way I do preiviously is first ssh one by one. And then find the hosts which are offline or windows. And write them down one by one. And then ssh to hosts except them. Let us assume the number of programs is less than the total available hosts. Can someone write a shell script to output the all available hosts to a file like "host_available"?
Here is the host file.
https://www.dropbox.com/s/vbz6w864y3...tlist.txt?dl=0
I am using ssh to connect the computers on campus. If the computer I am trying to connect is offline or using windows, the ssh will take long time, and finally it will failed. I write a shell script to generate the hostlist
Code:
#!/bin/bash
for i in `seq -w 1 28`
do
echo "c15-0330-$i.ad.mtu.edu"
# I would like to add a command here to see whether ssh c15-0330-$i.ad.mtu.edu it succeeds or not. And then output a #file which contains the all available host.
done
for i in `seq -w 1 20`
do
echo "c28-0112-$i.ad.mtu.edu"
done
for i in `seq -w 1 20`
do
echo "c28-112a-$i.ad.mtu.edu"
done

I do not how to set a certain time to see whether connection is successful or not (see the comment in the shell script).

SFTP Shell Script

Hi,
I am looking for a simple shell script that allows for sftp to be run from the server to another server (Windows). I would like the script to be passed parameters suchas destination server, Id, password, Directory structure/folder name, file name etc...
Need some help to know how to start with and it would be great if someone help me with any sample sftp shell script

Linux From Windows- Bash ,shell

Hello am a newbie to linux,
I tried to install cygwin for windows,all i need is i need to write a shell program for a batch file i already have, I am not able to do this.
My batch file content looks like

SET JAVA_HOME=..\jdk
SET CLASSPATH="%CLASSPATH%;../lib/A.jar;../lib/slf4j-api-1.6.1.jar;../lib/slf4j-simple-1.6.1.jar"

%JAVA_HOME%\bin\java.exe com.A ../conf/C.properties

PAUSE

this works perfectly, I try to write a shell program which is failing when i check it through cygwin. i am not able to set the export to java_home.
The pblm i face is say my current directory where my shell program is 'Z'
then i want to get back to 'y' where X has two sub folders y and z

X
-Y (is jdk )
-Z (where shell pgm resides)

cd ../ or any combination of cd doesnot work in my shell script.

Please help me. Any help is greatly appreciated

Bash Script Non-interactive Login Shell

Hi

I'm focusing on getting my head around interactive v non-interactive shells, both non-login and login. Basically what scripts are run and how local and global variables behave.

I'm pretty much there except for 'non-interactive login shells'. I understand that 'non-interactive' shells are started when a script is run. However, if I start my script with #!/bin/bash --login, then a 'non-interactive login' shell will be started.

In my mind I would have expected this to be the same as logging in from scratch, albeit without a user\password prompt. In this case I would have thought that any exported variables from the parent shell would be blown away. This doesn't appear to be the case. The 'non-interactive login' shell appears to inherit the environment of its parent 'interactive' shell.

Can anyone explain the purpose of a 'non-interactive login' shell and how they behave in this regard.

Hope this makes sense.

Cheers

Mike

First Time After Install, Run Configuration Script

Hello,

My job is having me get back into Linux. It has been awhile since I messed with it. My company releases Software that runs on Linux. As such, when we release a new version of the software, we have it packaged with the entire Linux OS. As such, when it is sent to our clients, they install, and then have to reconfigure, the Host Name, IP Address, Netmask, and Gateway. Our test environment consists of over ten different Linux boxes and configurations. To make life easier for me, I have written a shell script allowing me a menu to change all of these and to also enable or disable the gateway and how to set/change the localadm password.

I want the script available to users to be able to run it anytime they need to. It works great. I would like to add one more thing to this. I want to be able to run the script automatically on the very first boot after the installation. The script is set up where you have to log in as root to run it. So here is the process I want to happen:

Install Disk
System starts up for very first time after install
Automatically logs in as root and runs script
Exits as root.

I realize Linux will only do what I tell it to. How do I tell it to do this?

Issue With Unix Shell Script Getting Defunct

Hi,

We have couple of shell scripts , which get hung due to defunct issue. Could anyone please help me understand the possible reason? How do I handle this in my script?

Tree Cmd Is Not Working

Hi All,

Not able to find TREE command in EL6, its working fine in EL5. Need help on this.

Below are the details.



[root@localhost ~]# mkdir -p /college/sports/performer/cricket

[root@localhost ~]# tree /college/
-bash: tree: command not found

[root@localhost ~]# tree college/
-bash: tree: command not found

[root@localhost ~]# which tree
/usr/bin/which: no tree in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin: /usr/bin:/root/bin)

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023