Questions tagged [shell-scripting]

Programming in an Interpreted language executed by a running Shell

Filter by
Sorted by
Tagged with
1 vote
2 answers
564 views

Get a file's ctime, atime, mtime and extended attributes

I would like to display a file's ctime, mtime and atime along with whether it has extended attributes or not. There are 2 commands that can do this but I have not been able to combine them into a ...
1 vote
2 answers
3k views

Special char or wildcard in awk field separator

Would appreciate to know about the special char or wildcard in the following command: /sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}' What does the code below mean? awk -F ' *|:' '
1 vote
1 answer
1k views

Get OpenVPN client IP script

My machine get's an IP from OpenVPN server when connecting to the VPN gateway. This is tun0 on Ubuntu. I assume naming might be different for other systems that may connect to OpenVPN gateway. Is ...
2 votes
1 answer
4k views

A way to update the plain text password to ssha in Open ldap for 400K Users

Is there any command/extension available to update the "userPassword" attribute from a user object in LDAP server to SSHA hashed passsword from plain text? we found that users in LADP are stored in ...
-1 votes
1 answer
3k views

Bash add entry to fstab by script [closed]

I'm newbies in bash scripting and i try to write script that add entry for cifs windows share to fstab. I writed a litle script but i'm not shure if it will work fine. I haven't linux to test it Can ...
0 votes
1 answer
159 views

find files which are not currently in use

I'm trying to archive some older files, but don't want to touch all the files which are currently in use. What's the best way to ask find to exclude "in use" files? Right now I'm working on this ...
1 vote
1 answer
552 views

Trying to get pid from a script running as su -c

I am trying to get these scripts to work in an environment where the java application needs to run as user foobar no matter if it is started as root or foobar. So these are my modifications to the ...
2 votes
2 answers
2k views

pam_exec.so PAM module does not export variable PAM_USER as stated in the documentation

I'm trying to use the pam_exec.so PAM module to execute a script which needs to know the username/password coming from the application (OpenVPN in this case). I have a script that executes printenv &...
6 votes
1 answer
1k views

perl equivalent of sh -e

In /bin/sh and /bin/bash (and I guess a lot of other shells), starting scripts with #!/bin/sh -e (or executing set -e in someplace in the script) would cause the script to abort when any command line ...
0 votes
1 answer
53 views

how to put tabulator as parameter for sudo in sudoers file

I would like to give for specific user allowing to put tabulator as parameter to program. Full invoking looks like: sudo /sbin/vgs --units b --nosuffix --noheadings --separator 'TAB' I try to put it ...
2 votes
1 answer
461 views

Bash Function to Export .bashrc to a Remote Server

I am trying to write a bash function shown below. I am trying to scp my .bashrc to the target machine. I want to do modify the following function in the below two ways. I want to enter the password ...
0 votes
1 answer
3k views

Bash FTP login into Microsoft FTP Service, Invalid command

This is my script. As you can see it executes only 1 command (cd /) after connecting to a remote FTP server. It's very simple... but it doesn't work and give me "Invalid command". I don't understand ...
0 votes
1 answer
1k views

Escaping special characters while sourcing file in bash

I've written a script that sources a bash shell fragment. The shell fragment is supposed to be a kind of configuration file, basically it's a bunch of bash variable. The issue here is when some of ...
1 vote
1 answer
426 views

Bash Script to set Linux OS

I'm working on a bash script and ran into an issue. I'm pushing what I know from using normal if/fi statements and trying to use them to set variables related to picking up the OS version, such as RH ...
1 vote
2 answers
4k views

Executing local function code on a remote server

I am updating about 20 bash scripts that perform various server-side operational tasks, checking status / sending reports etc. On some environments these scripts will run locally, on others they need ...
0 votes
1 answer
2k views

How to run a shell script on all amazon ec2 instances that are part of a autoscaling group?

Can anyone please tell me how to run a shell script on all the ec2 instances that are part of a auto scaling group. The scenario is that i have a script that i want to run on many ec2 instances that ...
1 vote
1 answer
581 views

Export or Forward /var/spool/mail/USER (readable for customer)

there are some bounce mails in the /var/spool/mail/USER directory that failed to send. Now the customer receives all of those mails from us because he does not have direct access to them. I can ...
6 votes
3 answers
7k views

Simple dig output?

In a script I want to be able to write an IP address to somewhere easily, so I thought using dig (or a similar command) with back-ticks. However the simplest output I've been able to come up to wrt ...
2 votes
4 answers
5k views

how to run the dialog command with proccess

Please look on my code – ( bash script ) I want to display both dialogs on the screen on the same time, one dialog display the: tail –f from - /var/log/proccess1.log , and the second dialog ...
8 votes
3 answers
15k views

From a shell script, how can I check whether a table in MySQL database exists or not?

I am trying to write a script which allows a user to select the what manipulation he needs to do on a table. I want to check if the table exists or not. If it exists I will continue the other things ...
3 votes
1 answer
15k views

Passing variables in kickstart

I have a kickstart file that takes a hostname in the %pre section. I cannot seem to figure out how to get it two the first. As you see it sends the server information to another device which then ...
0 votes
1 answer
968 views

Bash linux increment variable

i am trying to increment a variable name inside a for loop to get 4 dynamic variable in each loop, this is an example while read line do for n in `seq 1 4` do ...
8 votes
1 answer
3k views

using temporary files vs pipes advantages and disadvantages

Say I have a file named jobs.csv and I would like to get the top 50k jobs done by Foo I can either do: # cat jobs.csv | sort -u | head -n 50000 > /tmp/jobs.csv # cat /tmp/jobs.csv | while read ...
4 votes
2 answers
5k views

Can I get an array as an option argument in bash script

I am writing a shell script and wants to pass multiple options in an argument. Is it possible to do that like using getopts? Requirement example: ./shell.sh -d db1 db2 should pass the values db1 ...
0 votes
2 answers
317 views

using powershell ; from a given location a of folder i want to validate and show the number of specific filetypes respective folder

Using powershell from a given location a of folder I want to validate and show the number of specific filetypes respective folder. I tried using the command to count the number of files in a folder I ...
3 votes
3 answers
20k views

power shell error: Cannot bind parameter

when i am trying to execute the below PowerShell command, i got error . The command : *PS cert:\currentuser\authroot> gci | where subject -like "UTN"* The error is below : Where-Object : Cannot ...
0 votes
1 answer
985 views

Why is my shell command not working?

I have a shell script that I'm working on that uses pssh to get the user id of a user on a remote server: for USER in $(cat users.txt); do runuser -l mike -c 'pssh -H server.mike.com -o /home/...
1 vote
0 answers
297 views

Powershell-Script is not exectued correctly

I have a power-shell-script which is called by a batch-file. The batch calls the script after it has set the execution policy to unrestricted. Currently the script does nothing more than writing a log-...
0 votes
1 answer
163 views

Issue with Bash Script On FreeBSD

I have the below bash script set to run every hour via cron as the root user. The purpose of this script is to email us when files have been uploaded to our sftp server and send us the logins. Here is ...
0 votes
1 answer
816 views

How to automate input for a repetitive script! Expect in Bash?

I am a junior sys admin. Reason I'm asking this question is because we don't have a senior sys-admin here who is proficient with scripting. Senior guys are at the head office and too busy for ...
1 vote
1 answer
1k views

Bash: Output of a command is written only to screen and not to another file while using tee, what could be the reason?

In order to troubleshoot some ftp connection error, I've been instructed to write a bash script which will infinitely connect to a remote frp server and get one file from there. ftpuser="ftpuser" ...
1 vote
0 answers
377 views

Linux: What could be the reason for random fails in updating passwd.byuid by running yppasswd?

In order to allow NOC users in my company to manage users through NIS I've created the following script: #!/bin/bash # This script will simplicate NIS user management. # You will not be able to ...
0 votes
1 answer
917 views

Executing command remotely on another linux server from a shell script

I have a shell-script which extract details from a log file between two dates and executes a command on the output to generate some report.The log files are on different server and scripts are ...
-1 votes
2 answers
598 views

Shell script output and input from c programs [closed]

I am new to Shell scripting.How am I supposed to take the output of a c program that i execute and give it as an input to another c program all using shell.
3 votes
1 answer
234 views

shell script (KSH) + set file to param & perform test between param and string

in my linux machine red-hat 5.1 - in ppp file - I have only the signature.pl string !!! remark - third application write the signature.pl string in to ppp file I set ppp file in $a param And ...
20 votes
1 answer
5k views

Shell command slow when using pipe, fast with intermediate file

Does anyone understand this huge difference in processing time, when using an intermediate file, or when using a pipe? I'm converting tiff to pdf using standard tools on a fresh debian squeeze server. ...
22 votes
1 answer
11k views

Ctrl-C in bash scripts

How do I implement ctrl+c handling in bash scripts so that the script is interrupted, as well as the currently running command launched by the script? (Imagine there's a script that executes some ...
0 votes
1 answer
568 views

Command fails during script execution in bash

I'm working on a bash script for automatize some common tasks but I'm having some issues and I need some help. This is the script I'm talking about: #!/usr/bin/env bash PS3='Please enter your choice:...
0 votes
3 answers
705 views

How can a script loop for 30 days?

I have a script, backup.sh, that creates a backup of a MySQL database and then SCPs it to a remote server. This works great, and I can run this once per day using crontab with no problems. However, ...
0 votes
1 answer
140 views

Creating enterprise init script (to support all Linux distros)

I'd like to create my own init script to make my program start at boot and be controlled via "service" utility in most popular Linux distributions. Requirements: it should be portable across ...
3 votes
2 answers
1k views

Looking for a way to wrap a command and give its own shell

I am working with the command line executing the same commands many times manually following the same pattern. Now I am looking for a way to simplify it by just typing the command only once. Lets ...
-3 votes
1 answer
184 views

Are these Advanced Features possible with a Bash Script on an Ubuntu Server? [closed]

I am trying to build a really flexible and useful Server Backup Bash Script. I have pretty much no experience working or building Bash scripts. I know that thousands of them exist in the wild but I ...
-7 votes
1 answer
142 views

Trying to understand linux script [closed]

I have this Linux script I found and I'm trying to understand it. Could someone please help me to understand it. The script if [ ! -d "/home/ftp/$PAM_USER" ]; then /bin/su - ftp -s /bin/sh -c "/...
0 votes
2 answers
1k views

Creating a log file inside a script works when manually run, but not when run through cron

I'm using Percona's Xtrabackup tools to back up a database nightly. I wrote a wrapper script to keep the proper number of backups around, write the output to a log file, and email the log file if the ...
11 votes
5 answers
17k views

Silent and scripted install of CPAN and Perl modules?

I need to install CPAN and some Perl modules automatically in a Scientific Linux (RHEL) installation script. Unfortunately the specific modules I want (at least one of them) cannot be found as RPM:s ...
1 vote
1 answer
119 views

SSH issues: keyfile and host file not working as expected

When I login to server with a key ssh -i /home/me/.ssh/id_rsa server everything goes without glitch. The key is authorized on the server. However if I try to do same from a shell script, I get a ...
0 votes
1 answer
792 views

124 emails sent at once while one should be sent every five minutes by cron if a certain web service stops running

So I set up a simple script to send an email alert when a certain web service stops running. It has a simple flow of: test = $( curl [address] | grep [a certain string in response] | wc -l ) if [ $...
4 votes
1 answer
3k views

How to schedule a Cron job for the second to the last day of each month

I want to schedule a task for the second to the last day of each month. I have read this great article about shell scripting the execution. I have also seen that you can use "L" to represent the last ...
0 votes
1 answer
851 views

Why is permission denied during pssh?

I am trying to add an ssh public key to a bunch of servers authorized_keys file. My thought was to use pssh and a list of hosts. To test, I tried to pssh to one host: pssh -i -H root@host echo ...
-4 votes
2 answers
78 views

What does this shell script mean? [closed]

#!/bin/bash /usr/sbin/ntpdate ntp.jst.mfeed.ad.jp I found such a script file,maybe it is used to confirm the time, can you explain it in detail?

1
6 7
8
9 10
13