[Solved] How can we take copy of a file using Bash script in Ubuntu?
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY sarika.k
3 years ago
Bash
0
comments comment

This article will help you to declare and print a variable using programming basic, intermediate shell scripts and how to use Bash script to copy files in Ubuntu. Actually, Bash is very simple and flexible UNIX shell scripting language which need some permission while executing.

Here I'm going to share some tips of Bash Script. It does not intend to be an advanced document. To clear your doubts or share your information about Bash, you can contact us.

Using Bash script we can declare and print a variable using,

#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING

To copy files using Bash script, we can use,

#!/bin/bash
srcdir="~/Desktop/bash_script"
dstdir="~/Desktop/bash_new/"
d=$(date +%m%d%y)
srcfile="hello_world.sh"

cp $srcdir $dstdir

#for srcfile in ${srcdir}
#do
#    dstfile=$(basename $srcfile)
#    dstfile=${dstfile/\./${d}\.}
#   cp $srcfile $dstdir/$dstfile
#done

Do you need more information about Bash script or commands, checkout now.


RELATED ARTICLE

more_horiz
close

on 11th December 2008 / by webmaster
Recently we had to provide support on a Red Hat Server where there were hundreds of users and the user directories organized into hierarchies. Normally we change to a users directory using cd ~username. We had some extra time on our hands and wanted to play with the /etc/passwd file and tried to use awk to do the same thing. The following one liner will do this the hard way :-) cd `(cat /etc/passwd|grep username|awk -F ":" '{print $6}')` The script works as follows. The home folders of all users are listed in the 6th column of the /etc/passwd file. The columns in the file are separated by colons. The 'cat' part will print the contents of the file to stdout which is piped to grep to find the line corresponding to the user. The grep will print just this line to the stdout which is then piped to awk which takes the content of the 6th column and prints it out. This string is passed as the return value from the back-quoted string and cd uses this path to change the directory. Using this served the purpose but the solution did not look very elegant. So we saved the following to a file /usr/local/bin/cduser cd `(cat /etc/passwd|grep $1|awk -F ":" '{print $6}')` and then added the following alias to ~/.bashrc alias cduser='. /usr/local/bin/cduser' The alias is required because a change directory command inside a script will only run in its own context and when control is returned to the calling shell the working directory would remain the same. The only way to work around is to source the script instead of executing it and this is done through the alias part. All is well that ends well. Now all we had to do to change to a users directory was to execute cduser username which is slightly more longer than cd ~username but you would be more wiser about shell scripting by figuring out the harder way :-). Linux Shell Scripting Bash Leave a reply Your email address will not be published. Required fields are marker * cherry (not verified) access_time 23 May 2019 - 18:37 alternatively: cd `(cat /etc/passwd|grep username|cut -d ':' -f 6` ;-) Add new comment
close

on 12th December 2009 / by webmaster
Asianet Dataline is an ISP in Kerala and they use a web browser based authentication system to log the user onto their network. One of their most popular plans the - Homenet 475 offers free unlimited downloads from 2AM to 8AM. Now if there was a way to turn on your system at 2AM, automatically login to Asianet and turn your download manager on and then shutdown at 8AM it would have been perfect. The only problem is that the http based authentication system makes it a bit unwieldy to automate. Well not really :-). We have created a bash script to automate this login process. Features - Automatically connect to Asianet Dataline without having to sign in via the browser. - In startup and free mode the script will keep the connection alive. - The script will automatically reconnect if connection breaks because of a power failure or a line problem. - In free mode the script will call any related startup and shutdown scripts placed inside the ~/.auto-login/startup and ~/.auto-login/shutdown folders. Setup Instructions a) Copy script to your favorite scripts folder. b) Edit script to update username and password with your Asianet login information. c) Add script to your startup process. See different ways of using the script below to know more. d) If you want to start and stop other applications at the time of starting the script then create a folder ~/.auto-login and inside that create sub-folders startup and shutdown. Place other scripts that have to be called during startup and shutdown of this script into the respective folders. Make sure that these scripts have their executable bit set. Different ways of using the script 1) Add a shortcut to your task bar to launch the script with the parameter "auto". Use this shortcut to start the connection with one click and stop the connection with one click. Remember that the connection will time out if there is no activity. But that should not be a problem because you can connect again with a single click. 2) Add the script to your startup process with parameter "startup". This will keep the script running in the background and the script will keep the connection alive with keep-alive requests. 3) Add the script to your startup process with parameter "free". This will keep the script running in the background and the script will connect only during the free download hours and then it will keep the connection alive with keep-alive requests until the free time ends. When free time ends it will disconnect the connection. In this mode the script will also run any related startup and shutdown scripts placed inside the ~/.auto-login/startup and ~/.auto-login/shutdown folders. The script is available at http://www.zyxware.com/software/utilities/asianet-auto-login.v.1.0.tar… The latest source can be downloaded from http://github.com/anoopjohn/Asianet-Auto-Login-Script If there are issues with the script please use the github issue queue at http://github.com/anoopjohn/Asianet-Auto-Login-Script/issues Internet Shell Scripting Bash Asianet Leave a reply Your email address will not be published. Required fields are marker * Vivek Thomas (not verified) access_time 23 May 2019 - 18:37 Thank you very much for this. Works great. Btw I had to add a --no-check-certificate option in the following line for it get the login URL. :) asianet_conn_url=`wget --quiet --no-check-certificate -O - www.zyxware.com|grep 'action='|sed 's/\(.*action="\)\(.*\)">/\2/g'` webmaster access_time 23 May 2019 - 18:37 In reply to Thank you very much for this. by Vivek Thomas (not verified) Changes duly made in git repo and credit given. Anoop JITHIN (not verified) access_time 23 May 2019 - 18:37 In reply to Thanks by webmaster Sir, Where is this "Favorite Scripts Folder" How Can I Copy A Script ie In Text Form To A Folde? Is Favorite Script Folder an attachment Of Internet Explorer Browser ? Please Tell Me About "START UP PROCESS" Can You Plese Explain What Should I Do Step By Step Considering Me As A Beginer. Jimmy (not verified) access_time 23 May 2019 - 18:37 Hi, I see the script. Can I use this script in Windows? If yes, please tell me the complete procedure to use this script in windows using the browser IE. Thanks Jimmy Anonymous (not verified) access_time 23 May 2019 - 18:37 Thank you very much for this. Works great. But I cant logout after use Add new comment
more_horiz
close

on 14th December 2012 / by thomas.john
The default method of changing a Drupal theme using the graphical Admin interface is familiar to most Drupal users. However a Drupal user is limited to changing only one theme at a time using this method and it is also slightly time consuming. What if you want to enable more then one theme at a time? Drupal provides a quicker way to change the theme using the bash command line. Read on to know how to enable multiple Drupal themes using the bash command line First we have to install drush on your server. Drush is a command line interface for accessing and working with Drupal After installing Drush lets check out all the existing themes in our Drupal site Type the following command from your Drupal server~/drush/drush pm-list --type=theme In sites/all/themes folder typedrush pm-list --type=theme This will display all themes in following order Package Name Status Version To enable a single theme with confirmation Type the following command from your Drupal server~/drush/drush pm-enable themename eg: ~/drush/drush pm-enable vert In sites/all/themes folder typedrush pm-enable themename eg: drush pm-enable business_blog To enable a single theme without confirmation Type the following command from your Drupal server~/drush/drush pm-enable themename --yes eg: ~/drush/drush pm-enable vert --yes In sites/all/themes folder type drush pm-enable themename --yes eg: drush pm-enable black_blog --yes List all themes with the associated info Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' Cut each column Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' '| cut -f1 -d' ' ~/drush/drush pm-list --type=theme | tr -s ' '| cut -f2 -d' '~/drush/drush pm-list --type=theme | tr -s ' '| cut -f3 -d' ' In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' '| cut -f1 -d' ' drush pm-list --type=theme | tr -s ' '| cut -f2 -d' ' drush pm-list --type=theme | tr -s ' '| cut -f3 -d' ' Display all theme names Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// Write all the themes to a themelist file Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// > themelist In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// > themelist Make sure that the file contains only theme name and not any other content. You can edit the file using following commandsless themelist nano themelist wc -l themelist Display all the themes from themelist file for i in `cat themelist`; do echo $i; done Enable all the themes (with confirmation required) Type the following command from your Drupal server for i in `cat themelist`; do ~/drush/drush en $i; done In sites/all/themes folder typefor i in `cat themelist`; do drush en $i; done Enable all the themes (without confirmation) Type the following command from your Drupal serverfor i in `cat themelist`; do ~/drush/drush en $i --yes; done In sites/all/themes folder typefor i in `cat themelist`; do /drush en $i --yes; done Hope you have find this article useful. Feel free to give your feedback via the comment form below . Drupal Bash Drupal Themes Drupal Theming Drush Leave a reply Your email address will not be published. Required fields are marker *
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.